Git存储:“无法应用于脏的工作树,请进行更改” [英] Git stash: "Cannot apply to a dirty working tree, please stage your changes"
问题描述
我正在尝试将之前存储的更改与 git stash pop
一起应用,并获取消息:
不能应用于肮脏的工作树,请为您的更改阶段添加
任何关于如何处理这个问题的建议?
当我必须将修改后的内容应用于脏的工作副本时,例如从存储中弹出多个变更集,我使用以下内容:
$ git stash show -p | git apply -3&& git stash drop
基本上它是
- 创建一个修补程序
- 管道应用命令
- 如果有任何冲突,则需要通过3
- creates a patch
- pipes that to the apply command
- if there are any conflicts they will need to be resolved via 3-way merge
- if apply (or merge) succeeded it drops the just applied stash item...
$ b $如果应用(或合并)成功,则会删除刚应用的存储条目。 b
我想知道为什么没有 -f
(force)选项适用于 git stash pop
就像上面的一行代码一样。
同时,您可能希望将这一行代码添加为git别名:
$ git config --global --replace-all alias.unstash \
'!git stash show -p | git apply -3&& git stash drop'
$ git unstash
感谢@SamHasler指出 -3
参数,它允许通过3路合并直接解决冲突。
I am trying to apply changes I stashed earlier with git stash pop
and get the message:
Cannot apply to a dirty working tree, please stage your changes
Any suggestion on how to deal with that?
When I have to apply stashed changes to a dirty working copy, e.g. pop more than one changeset from the stash, I use the following:
$ git stash show -p | git apply -3 && git stash drop
Basically it
I wonder why there is no -f
(force) option for git stash pop
which should exactly behave like the one-liner above.
In the meantime you might want to add this one-liner as a git alias:
$ git config --global --replace-all alias.unstash \
'!git stash show -p | git apply -3 && git stash drop'
$ git unstash
Thanks to @SamHasler for pointing out the -3
parameter which allows to resolve conflicts directly via 3-way merge.
这篇关于Git存储:“无法应用于脏的工作树,请进行更改”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!