git pull
命令有些地方我不明白。
我有一个 foobar
Git 存储库,其中包含两个文件,分别名为 f1
和 f2
。
首先,我使用此命令克隆此存储库:
git clone git@mycompany:foobar/foobar.git
我对 f1
和 f2
文件都做了一些错误的修改,将它们添加到 Git 索引然后提交。
git add -A
git commit -m 'a test wrong modification'
我现在决定这个修改是错误的,我想用远程版本替换我的文件。所以我使用 git pull
来做到这一点。
git pull
Already up-to-date.
Git 回答项目已经是最新的。我在做什么有什么问题吗?我应该如何继续将我的本地版本替换为远程版本?
最佳答案
git fetch origin
git reset --hard origin/master
这是关于 git pull git pull 的很好的解释
git fetch
命令将提交从远程存储库导入到本地存储库。结果提交存储为远程分支,而不是我们一直使用的普通本地分支。这使您有机会在将更改集成到您的项目副本之前查看更改。
命令 git pull <remote>
获取当前分支的指定远程副本,并立即将其 merge 到本地副本中。这与 git fetch <remote>
相同其次是 git merge origin/<current-branch>
.因为它正在进行 merge ,所以您的提交仍然存在。
做完之后 fetch
您可以使用重置命令重置您的工作副本。 Hard
是忽略本地副本中的任何更改。 git reset --hard origin/master
关于混帐 pull : replace local version with the remote version,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17336895/