简体   繁体   English

将所有文件从 master 移动到 Git 中的另一个分支

[英]Move all files from master to another branch in Git

I started working on a new project and from the beginning I pushed all my commits to master.我开始着手一个新项目,从一开始我就把所有的提交都推到了 master 上。 But now I think I should've used another branch for development and stored my code there and only have the production build in my master.但是现在我认为我应该使用另一个分支进行开发并将我的代码存储在那里,并且只在我的主控中构建生产版本。

Is there any way I can move all my files from master to a new branch?有什么办法可以将所有文件从 master 移动到新分支?

Yes.是的。

Create a branch on the current commit using git branch <whatever> .使用git branch <whatever>在当前提交上创建一个分支。 Then, run git log , and identify which commit is the latest "production" version (probably where you started working).然后,运行git log ,并确定哪个提交是最新的“生产”版本(可能是您开始工作的地方)。 git checkout that commit, and then git branch -f master to make the local master branch point there, and git push -f origin master to update the origin. git checkout that commit,然后git branch -f master使本地 master 分支点在那里,然后git push -f origin master更新源。 If you work collaboratively with other people on this repository make sure to update them - force pushing is a destructive action and might cause issues , see this SO question .如果您与此存储库上的其他人合作,请确保更新他们 -强制推送是一种破坏性操作,可能会导致问题,请参阅此 SO 问题

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

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