为什么每个分支的 git stash 不是唯一的?

发布于 2024-07-04 11:27:31 字数 102 浏览 12 评论 0原文

我想它允许将更改从一个分支移动到下一个分支,但这就是樱桃采摘的目的,如果您没有提交更改,也许您不应该移动它们?

我有时在错误的分支应用了错误的存储,这让我想知道这个问题。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

强辩 2024-07-11 11:27:31

git-stash 对我来说最有用,可以将尚未签入的更改移至与当前签出的分支不同的分支。

例如 - 我经常发现自己在错误修复分支上进行简单的更改; 却发现我正在做的改变比我最初想象的要复杂。 Git-stash 是将一组更改移动到不同分支的最简单方法。

git-stash is most useful to me to move not-yet-checked-in changes off to a different branch than the one that is currently checked out.

For example - I often find myself doing simple changes on a bug-fixes branch; only to find that a change I'm working on is more complex than I first guessed. Git-stash is the easiest way to move that set of changes to a different branch.

樱桃奶球 2024-07-11 11:27:31

从 Git 1.6 开始,您现在可以使用 Git 将存储应用到分支,

git stash branch name_of_new_branch

Git 将为您创建新分支,然后检查一下! 有关更多信息,请参阅

我猜您可以使用来移动存储

git stash branch <branch | new_branch> [<stash>]

并查看存储列表,请使用

git stash list

参考

As of Git 1.6, you can now apply stashes to branches using

git stash branch name_of_new_branch

Git will create the new branch for you, and check it out! For more information, see

I'm guessing you can move stashes around using

git stash branch <branch | new_branch> [<stash>]

and to see a list of your stashes, use

git stash list

Reference

海未深 2024-07-11 11:27:31

如果您想要一个从分支运行的“存储”,请执行以下操作以将更改存储在当前分支的新分支上。

git checkout -b new_stash
git commit -a -m "stashed changes"

撤消存储

git reset HEAD^
git branch -d new_stash

git stash 特别有用,因为您可以将更改拉入脏树中,即,如果您有未完成的编辑并且想要执行操作

git pull

但您不能,您可以存储您的更改,拉动然后应用存储

git stash
git pull
git stash apply
git stash clear

希望这样有帮助!

if you want a "stash" that runs off a branch do something like this to store your changes on a new branch off your current branch.

git checkout -b new_stash
git commit -a -m "stashed changes"

to undo the stash

git reset HEAD^
git branch -d new_stash

git stash is especially useful because you can pull changes into a dirty tree, i.e. if you have outstanding edits and want to do a

git pull

and you can't, you can stash your changes, pull and then apply the stash

git stash
git pull
git stash apply
git stash clear

hope this helped!

时光匆匆的小流年 2024-07-11 11:27:31

如前所述,如果您想要“每个分支存储”,那么您确实需要从现有分支中分叉出一个新分支。

此外,除了已经提到的事实之外,存储允许您拉入正在处理的分支,它还允许您在提交所有内容之前切换分支。 这对于通常意义上的挑选来说很有用,但对于挑选你的工作副本来说更有用。

例如,在处理功能分支时,我经常会注意到代码中与该分支无关的小错误或修饰杂质。 好吧,我马上解决这些问题。 当需要做出承诺时,我会选择性地提交相关更改,但不会进行修复和修饰。 相反,我将这些隐藏起来,这使我可以切换到我的稳定版次要修复分支,然后我可以在其中应用隐藏并单独提交每个次要修复。 (根据相关的更改,我还将再次隐藏其中一些,以切换到不同的功能分支,并在其中应用这些功能。)

这使我可以在我进行编程时深入到编程模式。我正在工作,不用担心我的代码是否正确管理。 然后,当我精神休息时,我可以回去仔细地将我的更改分类到所有正确的架子上。

如果存储不是全局的,那么这种类型的工作流程将很难完成。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文