git stash 更改适用于新分支吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6925099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git stash changes apply to new branch?
提问by Yash Desai
I was working on master branch, made some changes and then stashed them. Now, my master is at HEAD.
我在 master 分支上工作,做了一些改变,然后把它们藏起来。现在,我的主人在 HEAD。
But now, I want to retrieve these changes but to a new branch which branches from the HEAD version of the master branch.
但是现在,我想检索这些更改,但要检索到从主分支的 HEAD 版本分支的新分支。
How do i do this ?
我该怎么做呢 ?
回答by Andrejs Cainikovs
Is the standard procedure not working?
标准程序不起作用吗?
- make changes
git stash save
git branch xxx HEAD
git checkout xxx
git stash pop
- 做出改变
git stash save
git branch xxx HEAD
git checkout xxx
git stash pop
Shorter:
更短:
- make changes
git stash
git checkout -b xxx
git stash pop
- 做出改变
git stash
git checkout -b xxx
git stash pop
回答by Rodney Golpe
Since you've already stashed your changes, all you need is this one-liner:
由于您已经隐藏了您的更改,因此您只需要这个单行代码:
git stash branch <branchname> [<stash>]
git stash branch <branchname> [<stash>]
From the docs (https://www.kernel.org/pub/software/scm/git/docs/git-stash.html):
从文档(https://www.kernel.org/pub/software/scm/git/docs/git-stash.html):
Creates and checks out a new branch named <branchname> starting from the commit at which the <stash> was originally created, applies the changes recorded in <stash> to the new working tree and index. If that succeeds, and <stash> is a reference of the form stash@{<revision>}, it then drops the <stash>. When no <stash> is given, applies the latest one.
This is useful if the branch on which you ran git stash save has changed enough that git stash apply fails due to conflicts. Since the stash is applied on top of the commit that was HEAD at the time git stash was run, it restores the originally stashed state with no conflicts.
创建并签出一个名为<新的分支分支名称>开始从提交在该<藏匿>最初创建,适用记录在<修改藏匿>新的工作树和索引。如果成功,并且 < stash> 是 stash@{< revision>}形式的引用,则它会删除 < stash>。当没有给出< stash> 时,应用最新的。
如果您运行 git stash save 的分支已经更改到足以导致 git stash apply 由于冲突而失败,这将非常有用。由于 stash 应用在运行 git stash 时 HEAD 的提交之上,因此它会在没有冲突的情况下恢复最初的隐藏状态。
回答by Hamed Yarandi
If you have some changes on your workspace and you want to stash them into a new branch use this command:
如果您的工作区有一些更改,并且想要将它们存储到新分支中,请使用以下命令:
git stash branch branchName
It will make:
它会使:
- a new branch
- move changes to this branch
- and remove latest stash (Like: git stash pop)
- 一个新的分支
- 将更改移动到此分支
- 并删除最新的存储(例如:git stash pop)