只存储在git中的变化 - 是否有可能? [英] Stashing only staged changes in git - is it possible?

查看:104
本文介绍了只存储在git中的变化 - 是否有可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以隐藏我的阶段性变化?我遇到的情况是当我在给定时间处理过几个错误,并且有几个未分离的更改。我希望能够单独展示这些文件,创建我的.patch文件,并将其隐藏起来,直到代码被批准。这样,当它获得批准时,我可以隐藏我的整个(当前)会话,弹出该错误并推送代码。



我会以错误的方式回答这个问题吗?我是否误解了git如何以其他方式来简化我的过程?解析方案

是的,它真的可以用,相信或不是, DOUBLE STASH


  1. 放置您需要存储的所有文件。 b
  2. 运行 git stash --keep-index 。该命令将创建一个包含更改( staged和unstaged )的 ALL 的存储,但会将暂存的更改保留在工作目录中(仍处于暂存状态)。 li>
  3. 运行 git stash保存good stash

  4. 现在您的好的存储仅限阶段文件

现在,如果您在存储之前需要非分页文件,只需应用第一个存储( --keep-index ),现在你可以移除你存储的文件到好藏



享受

Is there a way I can stash just my staged changes? The scenario I'm having issues with is when I've worked on several bugs at a given time, and have several unstaged changes. I'd like to be able to stage these files individually, create my .patch files, and stash them away until the code is approved. This way, when it's approved I can stash my entire (current) session, pop that bug and push the code.

Am I going about this the wrong way? Am I misunderstanding how git can work in other ways to simplify my process?

解决方案

Yes, it is really possible with, believe or not, DOUBLE STASH:

  1. Stage all your files you need to stash.
  2. Run git stash --keep-index. This command will create a stash with ALL of your changes (staged and unstaged), but will leave the staged changes in your working directory (still in state staged).
  3. Run git stash save "good stash"
  4. Now your "good stash" has ONLY staged files.

Now if you need unstaged files before stash, simply apply first stash (the one created with --keep-index) and now you can remove files you stashed to "good stash".

Enjoy

这篇关于只存储在git中的变化 - 是否有可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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