[英]Is it possible to delete a single file (i.e the diff of one file) from git stash with several files
I'm looking for a way to delete a single change from a stash compiled of several changes, anyone knows of a way to do it? 我正在寻找一种方法来从一个由几个变化编译的存储中删除一个变化,有谁知道这样做的方法? The best way for to describe it (due to the fact that
git commit
and git stash
are so similar) is that I wish I knew a way to git commit --amend
the stash. 描述它的最佳方式(由于
git commit
和git stash
非常相似)是我希望我知道一种方法来git commit --amend
存储存储。
It all started when I git stash
a few changes before pulling from a shared repository. 这一切开始时我
git stash
从共享存储库前拉一些变化。 while I was trying to git pop
the code from the stash, I had a conflict (I couldn't resolve) with a file I didn't care for duo to the fact that I had a script to generate it automatically, and was more interested in the other files located in my stash. 当我试图从存储中
git pop
代码时,我有一个冲突(我无法解决)与一个我不关心的文件,因为我有一个自动生成它的脚本,而且更多对我藏匿处的其他文件感兴趣。
While I was looking for a solution I've found this Q : How would I extract a single file (or changes to a file) from a git stash? 当我在寻找解决方案时,我发现了这个问题: 如何从git存储中提取单个文件(或更改文件)? - it seemed promising, and was also given to someone else asking a similar question to mine, but it didn't help...
- 它看起来很有希望,并且还被其他人问我的类似问题,但它没有帮助......
No, there is no way to delete a single change from a stash - at least not with the high-level commands that git stash
provides. 不,没有办法从存储中删除单个更改 - 至少不能使用
git stash
提供的高级命令。 As a stash is internally just a commit, you could use the low-level commands to manipulate it, but that is likely more trouble than it is worth. 由于stash在内部只是一个提交,你可以使用低级命令来操作它,但这可能比它的价值更麻烦。
My rule of thumb is: If things start to get complicated with git stash
, it's time to convert the stash to a real commit (typically on a separate branch). 我的经验法则是:如果
git stash
开始变得复杂,那么是时候将存储转换为真正的提交(通常在单独的分支上)。 Then you can use all the nice git commands for manipulating commits (checkout, reset, rebase etc.). 然后你可以使用所有好的git命令来操作提交(checkout,reset,rebase等)。
In your case I'd recommend steps like this: 在你的情况下,我建议这样的步骤:
If git stash pop
produces a conflict, clean up your working copy (re-checkout the files with conflict markers, etc.). 如果
git stash pop
产生冲突,请清理工作副本(重新签出带有冲突标记的文件等)。
Then run: 然后运行:
git stash branch wip-branch
This will create and check out a new branch named "wip-branch", starting from the commit at which the stash was originally created. 这将创建并检出一个名为“wip-branch”的新分支,从最初创建存储的提交开始。 Then it will apply the changes from the stash.
然后它将应用来自存储的更改。 That way there cannot be a conflict, because the stashed changes are re-applied to the commit they are based on.
这样就不会发生冲突,因为隐藏的更改会重新应用于它们所基于的提交。
Now you have a real branch "wip-branch" with your stashed changes, which you can rebase, merge, cherry-pick etc. to your heart's content :-). 现在你有了一个真正的分支“wip-branch”,你可以根据自己的内容改变,合并,挑选等等.-)。
Note: While I used to use git stash
regularly, I have almost stopped, because creating a real (temporary) commit on a real branch is not much more work, and gives me more options (not to mention that I can use proper commit comments, so I don't forget what the changes mean). 注意:虽然我经常使用
git stash
,但我几乎停止了,因为在真正的分支上创建一个真正的(临时)提交并没有多少工作,并且给了我更多的选择(更不用说我可以使用正确的提交注释) ,所以我不会忘记这些变化意味着什么)。
Maybe it is easier to: 也许它更容易:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.