简体   繁体   中英

Local git repository is inconsistent with github repo

I use git for my source management, I have a local repository on my mac and a remote repository at github. They are BOTH suppose to be the same exact thing. I work by myself and I am the only programmer working on my web applications.. I can't get git to act right - with svn I could simply commit the code to the repository and BAM! The remote repository magically had the exact same files in it... Not in git, no, it just can't be that simple. I MUST read an entire damn book just to use the stupid thing.

So the question is, what is your development cycle like? I just want to have the exact same code at github as I have in my local git repository. Here's how I code:

I write code...add, edit, delete, modify files.... So I do this at the command line:

git add .  # this is *suppose* to add all files that are not part of the repository

git commit -m 'I commited this because...'

git push # send it to github

Now, after several weeks and hundreds of commits, github as slightly different code that I have in my local repository.

Please help me get this fixed before I trade git & open source for windows & svn or jump out of a window.

I'm sorry about the tone here, I'm just really upset that I keep finding inconsistencies in my source repositories. It's not a good feeling. I envision the one day where I lose my laptop and then github has old code in it. This just seems stupid.

Oh, one more thing... I don't want to have to always do git rm /some/long/path/to/file.txt when I remove a file. Is there an easier way? This is absolutely stupid and too time consuming.

Thank you for your help.

Br

git add . actually only adds files and changes to files already in the repo. Try using git add -all . to actually add removed files.

If you're looking to just remove files, and not do the other changes, you can use git add -u . - for more information, check out the git-add man page here: http://www.kernel.org/pub/software/scm/git/docs/git-add.html

I've started using git over svn just recently, and, I must admit, I had some hardships switching over at first, too. Good luck!

Github has a nice page here detailing on how to create, commit and push : http://help.github.com/creating-a-repo/ .

and particularly this:

混帐
(source: skitch.com )

You probably want git push origin master (you need to define origin before of course, read the information above) instead of just git push .

Another important thing to know is the git commit -a command, which simply commits all changed files etc., no need to git add them separately.

You might also want to check the output of git status to see if there are any suspicious things there which could be the cause of github not being an exact copy.

And FYI, svn is open source as well :)

"git status" gives me a big list of files that I have deleted on my local repository, but still exist on the remote repository. This is my whole point. I want the two repositories to be exactly identical. How can I make this happen???????????????????????????????????

If git status shows those files, you haven't added them to a commit and pushed it to the master repository yet. This is not Git's fault, it's yours. A version control system that automatically deleted stuff from the main repository because you deleted it on a local working copy would be a very dangerous version control system.

Do git commit -a (per http://www.kernel.org/pub/software/scm/git/docs/git-rm.html ) and it'll add all those removals to a commit. Commit and push and you should be up to date.

It would help if you could specify exactly how the remote repository differs from what you expect (eg what is in your working tree). The only issue you have indirectly identified is that the remote repository still contains files that you have deleted from your local working tree .

If “deleted files still exist in the remote repository” is your only problem, then you should switch from using git add . to git add -A . The former will only add new files and stage changes made in tracked files. The later will add new files, stage changes made in tracked files, and remove files that are no longer in the working tree. You can use --all instead of -A if you prefer the more mnemonic option name. Using -A / --all will obviate the need for git rm each/deleted/file .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM