仅使用git存储未分段的更改(不--keep-index) [英] Stash only unstaged changes with git (not --keep-index)

查看:42
本文介绍了仅使用git存储未分段的更改(不--keep-index)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我确实了解-keep-index .这不是我想要的,因为它仍然存储所有 更改,但将暂存的更改保留在工作树中.我只想存储未暂存的文件,如果可能的话,不要用 git stash --patch 再次添加所有更改.

First of all, I do know about --keep-index. This is not what I want because it still stashes all changes, but leaves the staged one in the worktree. I would like to only stash the unstaged files, if possible without adding all changes again with git stash --patch.

推荐答案

如果要存储索引(已暂存的索引)和工作树(尚未暂存的索引)之间的差异,这就是 git diff :

If you want to store the diff between the index (what's staged) and the worktree (what's not staged yet), this simply is git diff :

# store it :
git diff > stash.patch

# if you additionally want to put the unstaged changes away :
git stash -k

要稍后在工作树上(而不是在索引上)应用这些更改:请使用 git apply

To apply at later these changes on the worktree (not on the index) : use git apply

git apply stash.patch


您还可以使用存储在存储中的内容重新创建该差异:


You could also use what gets stored in the stash to re-create that diff :

# stash the changes :
git stash -k

# to reapply them on the worktree at a later time :
#   the 'unstaged changes' are the diff between 
#    - what the index was (stash^2)
#    - and what the worktree was (stash)
git diff stash^2 stash | git apply -

# again : 'git apply' will apply the changes on the *worktree*, not the index

这篇关于仅使用git存储未分段的更改(不--keep-index)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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