Git隐藏未缓存的内容:如何保存所有未上演的更改? [英] Git stash uncached: how to put away all unstaged changes?

查看:94
本文介绍了Git隐藏未缓存的内容:如何保存所有未上演的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设在git版本化的项目中进行了两组更改.一组已上演,另一组未上演.

Suppose two set of changes are made in a project versioned by git. One set is staged and the other is not.

我想通过在此状态下运行项目(提交之前)来重新检查分阶段的更改. 有什么简单的方法可以存放所有未暂存的更改,而仅保留已暂存的?因此,我需要未暂存的更改才能从我的项目中消失,而要存储在某个地方以备进一步工作.

I would like to recheck staged changes by running my project at this state (before commit). What is a simple way to put away all unstaged changes and leave only staged? So I need unstaged changes to disappear from my project, but to be stored somewhere for further work.

这听起来很像git stash命令.但是git stash会将未暂存和暂存的更改都放在我的项目之外.而且我找不到类似git stash uncached的东西.

This is sounds very much like git stash command. But git stash would put both unstaged and staged changes away from my project. And I can't find something like git stash uncached.

推荐答案

更新2:
我不确定为什么人们会抱怨这个答案,它似乎与我配合得很好,对于未处理的文件,您可以添加-u标志

Update 2:
I'm not sure why people are complaining about this answer, it seems to be working perfectly with me, for the untracted files you can add the -u flag

完整命令变为git stash --keep-index -u

这是git-stash帮助中的摘录

如果使用了--keep-index选项,则所有已添加到 索引保持不变.

If the --keep-index option is used, all changes already added to the index are left intact.

如果使用了--include-untracked选项,则所有未跟踪的文件 还藏起来,然后用git clean清理,离开工作 目录处于非常干净的状态.如果改用--all选项 那么除了 未跟踪的文件.

If the --include-untracked option is used, all untracked files are also stashed and then cleaned up with git clean, leaving the working directory in a very clean state. If the --all option is used instead then the ignored files are stashed and cleaned in addition to the untracked files.

这是它的外观的gif图像:

And this is a gif of how it looks:

更新:

我今天(2020年1月31日)针对git版本2.24.0再次测试了我的答案,但我仍然认为这是正确的,我在上面添加了有关未跟踪文件的小注释. 如果您认为它不起作用,请同时提及您的git版本.

I tested my answer again today (31/1/2020) against git version 2.24.0, and I still believe that it's correct, I added a small note above about the untracked files. If you think it's not working please also mention your git version.

旧答案:
如果使用--keep-index选项,则已添加到索引的所有更改均保持不变:

Old answer:
If the --keep-index option is used, all changes already added to the index are left intact:

git stash --keep-index

来自git-stash文档:

From the documentation of git-stash:

测试部分提交

当您要两个或两个以上时,可以使用git stash save --keep-index 从工作树中的更改中提交了更多提交,并且您想测试 提交前的每次更改:

Testing partial commits

You can use git stash save --keep-index when you want to make two or more commits out of the changes in the work tree, and you want to test each change before committing:

# ... 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 :

But, if you just want to visually check the staged changes only, you can try difftool:

git difftool --cached

这篇关于Git隐藏未缓存的内容:如何保存所有未上演的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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