简体   繁体   English

如何将我的主分支的内容移动到新的 Git 分支?

[英]How do I move the contents of my master branch to a new Git branch?

I've been making some vast changes on the master branch of my Git repository.我一直在我的 Git 存储库的主分支上进行了一些巨大的更改。 I'm pretty new to Git and so I'm wondering:我对 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的新分支。

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:)这应该足够了:)

Use git branch -m master old_master to rename master to something else.使用git branch -m master old_master将 master 重命名为其他名称。 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 checkout -b master HEAD~2之类的操作,根据您的需要创建新的主控(在这种情况下,直到前一个 HEAD 的第二次提交)现在添加/替换文件夹new_stuff并在master中提交

git checkout master; git reset --hard f1eb786

worked fine for me and seems less intrusive than deleting master temporarily.对我来说工作得很好,而且似乎比暂时删除 master 更少打扰。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM