一个项目,fork 出来,修改了其中一个文件,git commit & push,然后获取上游的更新,并和自己的代码 merge,merge 后我对原来那个文件的修改被合并,变成上游的代码,现在我想把该文件回退到之前我修改并提交的状态,但是我用 git log 查看的时候出现了标题说明的问题…十分不理解…
(图里,我是 hyzhang)
项目在这里
習慣沉默2017-04-24 16:02:42
Because you used -2
呀,然后合并来的上游修改比你的新,所以你自己的修改排在前2之外了。不要用-2
, check the complete history, find the version you want to restore, check it out and then commit.
过去多啦不再A梦2017-04-24 16:02:42
Install git extras, then execute git revert, it will handle everything for you
黄舟2017-04-24 16:02:42
Try it git log --pretty=oneline modules.rst
After seeing this interface, I still recommend tig
My clone
了你的库,然后我分别 checkout
到你之前的 commit
上然后创建新的分支,再进行 diff
operation, here are the results:
Modification history from fix typo and translation
到 Merge...
无 modules.rst
Modification history from add...
到 fix typo and translation
仍然无 modules.rst
Modification history from fix typo
到 add...
终于出现了 modules.rst
So it’s obvious git
的 log
记录没有错,你最近的几次 commit
并没有修改 modules.rst
文件,它又怎么会出现在 log
Where is it?
The last four commit
records:
According to the results of git diff
, it can be determined that the submission from fix typo
to add...
is for modules. rst
's most recent operation, so checking the log
of modules.rst
will definitely only show add...
this time. git diff
的结果,可以确定从 fix typo
到 add...
的这次提交中是对 modules.rst
最近的操作,所以查看 modules.rst
的 log
肯定只显示到 add...
这次 commit
git log --merges
command to display the for merge
: git log --merges
命令,显示用于 merge
的 commit
Did you find it? Compared with the previous
merge
, your merge
has a conflict
this time, and this conflict
is different from your The problem file modules.rst
is still related, so I analyzed that this should be the problem. It should be that your files conflicted, but you did not resolve the conflict, and merge
succeeded , these conflicts are ignored for unknown reasons, so they will not be entered into the history of log
as part of . Okay, it's time to take a rest. I hope the answer will be helpful to the questioner. :)merge
相比,你这次 merge
是存在 conflict
的,而且这个 conflict
和你的问题文件 modules.rst
还有关,所以我分析这应该就是问题所在,应该是你的文件产生了冲突,但是你没有解决冲突,而又 merge
成功,这些冲突不知道什么原因被忽略,所以它们不会作为 commit
的一部分进入 log