简体   繁体   English

本地git存储库与github repo不一致

[英]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. 我使用git进行源代码管理,我的mac上有一个本地存储库,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! 我自己工作,我是唯一一个在我的Web应用程序上工作的程序员。我不能让git行动正确 - 使用svn我可以简单地将代码提交到存储库和BAM! The remote repository magically had the exact same files in it... Not in git, no, it just can't be that simple. 远程存储库神奇地拥有完全相同的文件...不是在git中,不,它就不会那么简单。 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. 我只想在github上使用与我在本地git存储库中完全相同的代码。 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. 现在,经过几周和数百次提交,github与我在本地存储库中的代码略有不同。

Please help me get this fixed before I trade git & open source for windows & svn or jump out of a window. 在我交易git&open source for windows&svn或跳出窗口之前,请帮我解决这个问题。

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. 我设想有一天我丢失了我的笔记本电脑然后github有旧代码。 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. 哦,还有一件事......当我删除文件时,我不想总是做git rm /some/long/path/to/file.txt。 Is there an easier way? 有没有更简单的方法? This is absolutely stupid and too time consuming. 这绝对是愚蠢而且太耗时。

Thank you for your help. 谢谢您的帮助。

Br BR

git add . actually only adds files and changes to files already in the repo. 实际上只添加文件和更改已存在于repo中的文件。 Try using git add -all . 尝试使用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 . 如果您只想删除文件而不进行其他更改,可以使用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 - 有关更多信息,请查看git-add手册页: 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. 我刚刚开始在svn上使用git,而且,我必须承认,我最初也有一些困难。 Good luck! 祝好运!

Github has a nice page here detailing on how to create, commit and push : http://help.github.com/creating-a-repo/ . Github在这里有一个很好的页面,详细介绍了如何创建,提交和推送: http//help.github.com/creating-a-repo/

and particularly this: 特别是这个:

混帐
(source: skitch.com ) (来源: 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 . 你可能想要git push origin master (你需要先定义原点,然后阅读上面的信息)而不是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. 另一个要知道的重要事情是git commit -a命令,它只是提交所有已更改的文件等,不需要单独git add它们。

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. 您可能还想检查git status的输出,看看是否有任何可疑的东西可能是github不是精确副本的原因。

And FYI, svn is open source as well :) 而且,仅供参考,svn也是开源的:)

"git status" gives me a big list of files that I have deleted on my local repository, but still exist on the remote repository. “git status”给了我一个很大的文件列表,我在本地存储库中删除了这些文件,但仍存在于远程存储库中。 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. 如果git status显示这些文件,则表示尚未将它们添加到提交中并将其推送到主存储库。 This is not Git's fault, it's yours. 这不是Git的错,它是你的。 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. 执行git commit -a (根据http://www.kernel.org/pub/software/scm/git/docs/git-rm.html ),它会将所有这些删除添加到提交中。 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 . 如果“已删除的文件仍存在于远程存储库中”是您唯一的问题,那么您应该从使用git add .切换git add . to git add -A . 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. 如果您更喜欢更多的助记符选项名称,则可以使用--all而不是-A Using -A / --all will obviate the need for git rm each/deleted/file . 使用-A / --all将不需要git rm each/deleted/file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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