为什么不是每个分支独特的git存储? [英] Why isn't the git stash unique per branch?

查看:102
本文介绍了为什么不是每个分支独特的git存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想它允许将分支从一个分支转移到另一个分支,但这正是樱桃采摘的目的,如果你没有对变更做出承诺,或许你不应该将它们移动?



我偶尔会在错误的分支处应用错误的藏匿处,这让我不禁想知道这个问题。

解决方案如前所述,如果你想要一个per-branch stash,你真的想要一个新的分支从现有的分支中分出来。



另外,除了已经提到的隐藏允许你插入你正在处理的分支的事实之外,它还允许你在提交所有内容之前切换分支。这对于通常意义上的樱桃采摘非常有用,例如樱桃采摘您的工作副本

F.ex。,在工作部门工作时,我会经常注意到与该部门无关的代码中的小错误或化妆品杂质。那么,我立即修复这些问题。当时间到来时,我有选择地提交相关更改,但不包括修复和化妆品。相反,我隐藏了那些,这使我可以切换到我的小修补程序稳定分支,然后我可以应用存储并分别提交每个小修补程序。 (根据问题的变化,我将再次隐藏其中的一些内容,切换到不同的功能分支,我在那里应用那些。)



这使我可以在工作时深入编程模式,而不必担心我的代码的正确图书馆管理。然后,当我休息一下时,我可以返回并仔细地将我的更改分类到所有正确的货架上。



如果存储空间不是全局的,则此类工作流将会更加困难。


I suppose it allows for moving changes from one branch to the next but that's what cherry picking is for and if you're not making a commit of your changes, perhaps you shouldn't be moving them around?

I have on occasion applied the wrong stash at the wrong branch, which left me wondering about this question.

解决方案

As mentioned, if you want a "per-branch stash," you really want a new branch forking off from the existing branch.

Also, besides the already mentioned fact that the stash allows you to pull into a branch that you’re working on, it also allows you to switch branches before you have committed everything. This is useful not for cherry-picking in the usual sense so much as for cherry-picking your working copy.

F.ex., while working on a feature branch, I will often notice minor bugs or cosmetic impurities in the code that aren’t relevant to that branch. Well, I just fix those right away. When time comes to commit, I selectively commit the relevant changes but not the fixes and cosmetics. Instead I stash those, which allows me to switch to my minor-fixes-on-stable branch, where I can then apply the stash and commit each minor fix separately. (Depending on the changes in question, I will also stash some of them yet again, to switch to a different feature branch, where I apply those.)

This allows me to go deep into programming mode when I am working, and not worry about proper librarianship of my code. Then when I take a mental break, I can go back and carefully sort my changes into all the right shelves.

If the stash weren’t global, this type of workflow would be far more difficult to do.

这篇关于为什么不是每个分支独特的git存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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