强制git stash覆盖添加的文件 [英] Force git stash to overwrite added files

查看:130
本文介绍了强制git stash覆盖添加的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些在git中未跟踪的文件.我做了一些更改并想提交它们,但是意识到我忘记了首先检入未修改的文件.所以我藏了文件,然后添加了未修改的版本.

I have some files which were untracked in git. I made some changes and wanted to commit them, but realised I had forgotten to check in the unmodified files first. So I stashed the files, then added the unmodified versions.

然后,当我将存储空间应用于存储库时,由于已经添加了文件,因此发生冲突.

Then when I apply the stash to the repository, I get conflicts due to the files having already been added.

如何应用存储,并强制使用存储中的版本优先于存储库中的原始版本?

How can I apply the stash, and force the versions in the stash to be used in preference to the originals in the repository?

谢谢

推荐答案

使用git checkout代替git stash apply:

$ git checkout stash -- .
$ git commit

这会将当前目录中的所有文件还原到其隐藏版本.

This will restore all the files in the current directory to their stashed version.

如果应保留工作目录中其他文件的更改,那么这是一个比较宽松的选择:

If there are changes to other files in the working directory that should be kept, here is a less heavy-handed alternative:

$ git merge --squash --strategy-option=theirs stash

如果索引中有更改,或者合并将触摸具有本地更改的文件,则git将拒绝合并.可以使用以下方式从存储中检出单个文件

If there are changes in the index, or the merge will touch files with local changes, git will refuse to merge. Individual files can be checked out from the stash using

$ git checkout stash -- <paths...>

或与之交互

$ git checkout -p stash

这篇关于强制git stash覆盖添加的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆