gpt4 book ai didi

git - 仅使用 git 存储未暂存的更改(而不是 --keep-index)

转载 作者:行者123 更新时间:2023-12-03 16:23:48 36 4
gpt4 key购买 nike

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

最佳答案

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

# store it :
git diff > stash.patch

# if you additionally want to put the unstaged changes away :
git stash -k
稍后在工作树(而不是索引)上应用这些更改:使用 git apply
git apply stash.patch

您还可以使用存储在存储中的内容来重新创建该差异:
# 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 - 仅使用 git 存储未暂存的更改(而不是 --keep-index),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49301304/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com