Git 重置并比拉

Git reset and than pull

在我的场景中,我正在做:

git reset <commit>

紧随其后的是:

git pull --ff-only

根据我对git的理解,这个动作应该会成功,然后重做(快进)我重置的历史。

但是,我得到: error: The following untracked working tree files would be overwritten by merge: 在我的许多文件上,操作失败。

有谁知道为什么它没有像我预期的那样工作?谢谢!

git reset 只有刚刚添加到索引的未暂存文件..

pull 成功之前,您至少需要 reset --hard(如果您确定没有任何正在进行的工作)。

re-do (fast forward) the history that I reset.

不完全是:它将获取然后 (git pull --ff-only):

Refuse to merge and exit with a non-zero status unless the current HEAD is already up-to-date or the merge can be resolved as a fast-forward.

它没有"fast-forward the history that you reset":重置与它无关:如果您之前进行了自己的本地提交,那么无论是否重置,合并都不会是快进的(除非您重置很难 origin/master,失去你的本地提交)。

git reset <commit>其实就是执行git reset --mixed <commit>(因为是默认的)

--mixed--soft--hard选项供您选择:

--soft

Does not touch the index file or the working tree at all (but resets the head to , just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.

--mixed

Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action. If -N is specified, removed paths are marked as intent-to-add.

--hard

Resets the index and working tree. Any changes to tracked files in the working tree since are discarded.

More option of git reset, you can refer git book.

根据您的情况,您可以改用 git reset --hard <commit>