反转导致补丁失败的 git 存储

Reversing a git stash resulting in patch failed

我做了一个

git stash

然后

git rebase origin/master

都成功了。

但是

git stash apply 

不太开心:​​

$git stash apply
Auto-merging yarn/pom.xml
CONFLICT (content): Merge conflict in yarn/pom.xml
Auto-merging unsafe/pom.xml
CONFLICT (content): Merge conflict in unsafe/pom.xml
Auto-merging tools/pom.xml
CONFLICT (content): Merge conflict in tools/pom.xml
Auto-merging streaming/pom.xml
CONFLICT (content): Merge conflict in streaming/pom.xml
Auto-merging sql/hive/pom.xml
CONFLICT (content): Merge conflict in sql/hive/pom.xml
Auto-merging sql/hive-thriftserver/pom.xml
CONFLICT (content): Merge conflict in sql/hive-thriftserver/pom.xml
..

恢复 apply 的共识方法似乎是:

$git stash show -p | git apply -R

然而这会导致:

error: patch failed: assembly/pom.xml:20
error: assembly/pom.xml: patch does not apply
error: patch failed: bagel/pom.xml:20
error: bagel/pom.xml: patch does not apply
error: patch failed: core/pom.xml:20
error: core/pom.xml: patch does not apply
error: patch failed: examples/pom.xml:20
error: examples/pom.xml: patch does not apply
error: patch failed: external/flume-assembly/pom.xml:20
..  and so on ..

那么有什么方法可以把整个stash apply回滚吗?

您恢复隐藏更改失败的原因与应用隐藏更改的原因相同:基础内容更改太多,因此补丁不太适合。

如果您只想将所有文件还原为 HEAD 的内容,您只需要:

git reset --hard

来自手册:

   git reset [<mode>] [<commit>]
       This form resets the current branch head to <commit> and possibly
       updates the index (resetting it to the tree of <commit>) and the
       working tree depending on <mode>. If <mode> is omitted, defaults to
       "--mixed". The <mode> must be one of the following:

       --hard
           Resets the index and working tree. Any changes to tracked files
           in the working tree since <commit> are discarded.