假设在 git 版本控制的项目中进行了两组更改。一组已上演,另一组则未上演。
我想通过在此状态(提交之前)运行我的项目来重新检查分阶段的更改。放弃所有未暂存的更改并仅保留暂存的更改的简单方法是什么?因此,我需要未暂存的更改从我的项目中消失,但存储在某个地方以供进一步的工作。
这听起来很像git stash
命令。但git stash
会将未分阶段和分阶段的更改从我的项目中剔除。我找不到类似的东西git stash uncached
.
更新2:
我不知道为什么人们会抱怨这个答案,它似乎对我来说工作得很好,对于未处理的文件,你可以添加-u
flag
完整的命令变为git stash --keep-index -u
这是来自git-stash
help
如果使用 --keep-index 选项,则所有更改都已添加到
索引保持不变。
如果使用 --include-untracked 选项,则所有未跟踪的文件
也藏起来,然后用 git clean 清理,留下工作
目录处于非常干净的状态。如果使用 --all 选项
然后除了以下文件之外,被忽略的文件也会被隐藏和清理
未跟踪的文件。
这是它的外观 gif:
Update:
Even though this is the selected answer, a lot have pointed out that the [answer below](https://stackoverflow.com/a/34681302/292408) is the correct one, I recommend checking it out.
我今天(2020年1月31日)再次针对 git 版本测试了我的答案2.24.0
,并且我仍然相信它是正确的,我在上面添加了关于未跟踪文件的小注释。
如果您认为它不起作用,请同时提及您的 git 版本。
旧答案:
If the --keep-index
使用选项时,已添加到索引的所有更改都将保持不变:
git stash --keep-index
来自的文档git-stash https://git-scm.com/docs/git-stash:
测试部分提交
您可以使用git stash save --keep-index
当你想做两个或
更多提交了工作树中的更改,并且您想要测试
提交前的每个更改:
# ... hack hack hack ...
$ git add --patch foo # add just first part to the index
$ git stash save --keep-index # save all other changes to the stash
$ edit/build/test first part
$ git commit -m 'First part' # commit fully tested change
$ git stash pop # prepare to work on all other changes
# ... repeat above five steps until one commit remains ...
$ edit/build/test remaining parts
$ git commit foo -m 'Remaining parts'
但是,如果您只想直观地检查分阶段的更改,您可以尝试difftool https://git-scm.com/docs/git-difftool:
git difftool --cached
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)