如何将主分支的内容移动到新的 Git 分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6577695/
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
How do I move the contents of my master branch to a new Git branch?
提问by Spyros
I've been making some vast changes on the master branch of my Git repository. I'm pretty new to Git and so I'm wondering:
我一直在我的 Git 存储库的 master 分支上进行一些巨大的更改。我对 Git 很陌生,所以我想知道:
How can I move my current master branch to a new branch and recreate my master branch from scratch for a particular folder of files?
如何将当前的主分支移动到新分支并从头开始为特定的文件文件夹重新创建主分支?
As an example, I have another folder, like new_stuff
, that contains the new files to be added to the master branch, and that old master is a new branch named old_master
.
例如,我有另一个文件夹,例如new_stuff
,其中包含要添加到 master 分支的新文件,而旧 master 是一个名为old_master
.
回答by Tadeck
Within the directory of the repository, in the command line type the following:
在存储库的目录中,在命令行中键入以下内容:
git branch -m master old_master
git branch master
This should be enough :)
这应该足够了:)
回答by manojlds
Use git branch -m master old_master
to rename master to something else. Then do something like git checkout -b master HEAD~2
to create the new master as per your needs ( in this case till the 2nd commit from previous HEAD ) Now add / replace the folder new_stuff
and commit in master
使用git branch -m master old_master
掌握重命名为别的东西。然后git checkout -b master HEAD~2
根据您的需要做一些类似的事情来创建新的主(在这种情况下,直到前一个 HEAD 的第二次提交)现在添加/替换文件夹new_stuff
并提交master
回答by Quintus
git checkout master; git reset --hard f1eb786
worked fine for me and seems less intrusive than deleting master temporarily.
对我来说效果很好,而且似乎没有暂时删除 master 的干扰。