git pull master 的问题与 origin master 不同步
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18907689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Issue with git pull master is out of sync with origin master
提问by user1769790
These are the sequence of steps I have performed:
这些是我执行的步骤序列:
- committed my changes in branch to local master (commit id
dc9afg2k) git fetch origin master && git merge origin mastergit checkout mastergit pull(this pulled all recent changes)git fetch origin master && git merge origin mastergit reset --hard origin/mastergit checkout branchgit bloggit reset --hard dc9afg2k(commit successful)git checkout mastergit log(this was gone back to 2 days ago).git pull(masteris not updating with currentorigin/master).
- 将我在分支中的更改提交给本地主节点(commit id
dc9afg2k) git fetch origin master && git merge origin mastergit checkout mastergit pull(这拉动了所有最近的变化)git fetch origin master && git merge origin mastergit reset --hard origin/mastergit checkout branchgit bloggit reset --hard dc9afg2k(提交成功)git checkout mastergit log(这又回到了 2 天前)。git pull(master不是用当前更新origin/master)。
回答by VonC
An out of sync mastercan happen when the remote repo has received a forced push(git push --force) which rewrite the history.
master当远程存储库收到重写历史记录的强制推送( git push --force)时,可能会发生不同步。
If you have done commits of your own on master:
如果您已经在 master 上完成了自己的提交:
make a branch (to remember the current master state)
git branch old_mastermake sure you don't have any private file you need to save.
创建一个分支(记住当前主状态)
git branch old_master确保您没有任何需要保存的私人文件。
That would be:
那将是:
git fetch origin
git reset --hard origin/master
git clean -f -d
(you can preview the last cleaning steap with a '-n' option: git clean -n -f -d)
(你可以用一个“预览上次清洗STEAP -n”选项:git clean -n -f -d)
Note that git fetch origin master && git merge origin mastercould be a git pull origin master: the interest of keeping the two steps separated is to look at the difference between masterand origin/masterbefore the merge.
If you don't make that diff, then a git pullis simpler.
请注意,这git fetch origin master && git merge origin master可能是git pull origin master: 将两个步骤分开的目的是查看合并之前master和之间的差异origin/master。
如果你不做那个差异,那么 agit pull更简单。

