Git:如何将自上次提交以来的更改移动到新分支

发布于 2024-09-09 05:44:08 字数 102 浏览 2 评论 0原文

我一直在一个我们可以称之为“A”的分支上工作。我刚刚意识到,自上次提交以来我添加的代码应该位于特定的(实验)分支中,而不是“A”中。如何将更改提交到新分支并让分支“A”保持上次提交时的状态?

I have been working on a branch which we can call "A". I just realized that the code I have added since I last committed should rather be in a specific (experimental) branch, but not in "A". How can I commit the changes to a new branch and leave branch "A" as it was when I last committed?

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

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

发布评论

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

评论(2

自找没趣 2024-09-16 05:44:08

如果更改已暂存或您的工作目录,您可以简单地检出到新分支,如下所示:

git checkout -b branch_name

然后您可以直接提交到新分支。

If the changes are staged or your working directory, you can simply checkout into a new branch like so:

git checkout -b branch_name

You can then commit directly into the new branch.

习ぎ惯性依靠 2024-09-16 05:44:08
git stash
git checkout branch-A
git stash pop
git stash
git checkout branch-A
git stash pop
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文