将当前更改放入新的 Git 分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4746672/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:53:56  来源:igfitidea点击:

Put current changes in a new Git branch

gitgithubgit-branch

提问by Noam

I've been editing some modules on the master branch but I haven't committed them. I'm now thinking that these changes should really be on an experimental branch and not the master branch.

我一直在 master 分支上编辑一些模块,但我还没有提交。我现在认为这些更改真的应该在实验分支上而不是在主分支上。

How can I get these edits into an experimental branch? Copy them to some temp location, create the branch, and then copy them back in?

如何将这些编辑放入实验分支?将它们复制到某个临时位置,创建分支,然后将它们复制回?

And how do I configure things so that when I do a git push from the new experimental branch it will it go into a branch of the same name in my GitHub repo?

以及如何配置东西,以便当我从新的实验分支执行 git push 时,它会进入我的 GitHub 存储库中的同名分支?

回答by Antoine Pelisse

You can simply check out a new branch, and then commit:

您可以简单地检出一个新分支,然后提交:

git checkout -b my_new_branch
git commit

Checking out the new branch will not discard your changes.

签出新分支不会放弃您的更改。