应用 git stash 时如何忽略空格?

Eli*_*ria 2 git git-stash

我在 git stash 中有一些修改,我想使用git stash pop或应用它们git stash apply。但是我在存储更改的文件中更改了一些缩进,当我尝试应用存储时,我遇到了一堆合并冲突。有没有办法忽略空白,同时将藏匿,类似-Xignore-all-space的选项git merge

我试过了git stash apply -Xignore-all-space stash@{2},它告诉我error: unknown switch `X'

tor*_*rek 5

不要试图用git stash. 使用完整的 Git 工具套件。

好的,但你已经有一个藏匿处。幸运的是,有一种非常简单的方法可以存储转换为临时分支,使用git stash branch

git status    # make sure all is clean; if not, commit or stash
Run Code Online (Sandbox Code Playgroud)

然后:

git stash branch temp-branch stash@{2}
git status
git commit     # optional: use if desired to save index before adding
git add ...    # add all files as needed
git commit     # make the commit
Run Code Online (Sandbox Code Playgroud)

现在回到你的分支上使用git mergegit cherry-pick或任何你想与工作承诺在尖端temp-branch。这些-X选项现在可用。

请注意,git stash branch将运行git stash drop stash@{2}. 没关系,因为现在您有一个完整的分支,命名为temp-branch(或您选择的任何其他名称)。

(你可以做这个,有点,小心,git cherry-pick直接用stash@{2},但很难和痛苦;git stash branch方法有点笨拙,但没有痛苦。如果你真的想直接做,请记住这是 reflog 条目 #2 of refs/stash,并且 stash 提交w采用合并的形式,第一父级是“stash bag”所依赖的提交。)