它总是在工作中发生,某人不小心将某件事提交给了主人,而不是交给了预期的功能分支,然后该人尝试解决该问题,只是使更改突然消失。我搜索了很多东西,找不到文档说明这种情况的发生原因或解决方法。
以下是重现步骤:
$ git init
$ echo hello world > testfile
$ git add testfile
$ git commit -m 'init'
$ git branch A
$ echo abc >> testfile
$ git commit -am 'append abc'
$ git revert HEAD --no-edit
$ git checkout A
$ echo fff > secondfile
$ git add secondfile
$ git commit -m 'Add second file'
$ git cherry-pick master^
Run Code Online (Sandbox Code Playgroud)
此时,git历史记录如下所示:
$ git log --oneline --all --graph --decorate
* ac6f9b4 (HEAD -> A) append abc
* …Run Code Online (Sandbox Code Playgroud) git ×1