我在主分支上工作,做了一些更改,然后将它们隐藏起来。现在,我的主人在HEAD。

但是现在,我想检索这些更改,但是要从主分支的HEAD版本分支到一个新分支。

我该怎么做呢?


当前回答

既然你已经存储了你的更改,你所需要的就是这一行代码:

Git stash branch <branchname> [<stash>]

来自文档(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.

其他回答

如果你在你的工作空间中有一些变化,你想把它们隐藏到一个新的分支中,使用这个命令:

git stash branch branchName

它将使:

一个新的分支(从最初创建存储的提交开始) 将更改移动到该分支 并删除最新的stash(如:git stash pop)

运行此命令后,您将希望git添加更改并提交它们。

标准程序不管用吗?

做出改变 Git保存 git branch xxx HEAD Git结帐XXX Git隐藏pop

短:

做出改变 git藏 Git checkout -b XXX Git隐藏pop

既然你已经存储了你的更改,你所需要的就是这一行代码:

Git stash branch <branchname> [<stash>]

来自文档(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.