简体   繁体   English

新到 Git 版本控制

[英]New to Git Version Control

I am new to git and i have ran into an issue.我是 git 的新手,我遇到了一个问题。 I created a feature branch from the master branch and did some commits, even pushed them.我从主分支创建了一个特性分支并做了一些提交,甚至推送了它们。

After I realized I was supposed to create my feature branch from another branch which is created from the master.在我意识到我应该从另一个从 master 创建的分支中创建我的特性分支之后。 Any suggestions, if there is any workaround here or do I just need to create the new branch as I was supposed to and write all the code again.任何建议,如果这里有任何解决方法,或者我只需要按照我应该的那样创建新分支并再次编写所有代码。

Thanks.谢谢。

One way to do it is with git rebase .一种方法是使用git rebase

Standing in the branch where you made the changes, after creating the other branch where you should have made the commits在创建另一个应该进行提交的分支之后,站在您进行更改的分支中

git rebase --interactive newbranch

Select the commits to pick and push. Select 提交选择和推送。

Another, equivalent way to do it is manually reverting the commits, stashing the changes and applying them to the other branch.另一种等效的方法是手动恢复提交,存储更改并将它们应用到另一个分支。

Stash the changes, in your feature branch where you added the commits将更改存储在添加提交的功能分支中

git reset --soft HEAD~{NUMBER OF COMMITS}
git stash

Check out the other branch and pull the latest changes查看其他分支并提取最新更改

git checkout otherbanch
git pull origin otherbanch

Create a new feature branch to apply the changes to创建一个新功能分支以将更改应用到

git checkout -b newbranch

Apply the stashed changes应用隐藏的更改

git stash apply

Fix conflicts if necessary, commit and push.必要时修复冲突,提交并推送。

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

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