我的当前分支已经将某些文件移动到不同的文件夹中,并且创建了一个存储库,对于那些位于旧文件夹中的文件进行了更改。如何正确应用这个存储库而不会破坏任何东西,并希望了解最简单的方法。
Move some files, only those that are required by a git stash show
, back to old place:
git mv file old_place/file
Apply stash to those files:
git stash pop
Merge the changes, if any:
vim ...
git add ...
Move files back to the proper places:
git mv old_place/file file
之后,您将获得应用stash的添加到index文件中。
peff
)于2016年12月6日提交的commit 9d4e28e。
(由Junio C Hamano -- gitster
--于2016年12月19日合并至commit db09f21)
stash
: 偏爱管道而不是git-diff
:当配置了
diff.renames
(从Git 2.9开始,默认情况下启用,这使得情况变得更糟),“git stash
”会出现问题,如果一个文件被删除,另一个内容非常相似的文件被添加。在创建存储时,我们需要查看工作树和HEAD之间的差异,并使用git-diff porcelain进行操作。
因为git-diff
默认启用重命名等瓷砖配置,这至少会导致一个问题。--name-only
格式将不提及重命名的源端,这意味着我们将无法存储作为重命名一部分的删除。我们可以通过传递
--no-renames
来解决该问题,但这是更大问题的症状。 我们应该在这里使用diff-index
plumbing,它默认情况下没有启用重命名,也不遵守任何可能令人困惑的配置选项。
这意味着以下内容将起作用:
mv file renamed &&
git add renamed &&
git stash &&
git stash apply
renamed
'的文件,而不是名为'file
'的文件(在git stash
之前作为'renamed
'移动)。