[英]What shall I do after my feature branch has been merged into master but I have continued to work on it?
I just realized that my coworker has merged my feature branch into the master branch in Github, while I have been continuing working on my feature branch on my local machine since his merge. 我刚刚意识到我的同事已将我的功能分支合并到Github的master分支中,而自从他合并以来,我一直在我的本地计算机上继续从事我的功能分支。 Now I have just git add
some new changes on the feature branch, without git commit
yet. 现在我只是git add
在feature分支上git add
一些新的更改,还没有git commit
。
If I realized that immediately when he made the merge, I would have pulled the master and then create a new feature branch and work on the new feature branch. 如果我立即意识到他进行合并时,我会拉起母版,然后创建一个新的功能分支,并在新的功能分支上工作。
What shall I do now? 我现在该怎么办? Will the answer be different, depending on whether I have run git add
, git commit
, or git push
? 答案会有所不同,具体取决于我是否已运行git add
, git commit
或git push
?
Thanks. 谢谢。
I am not confident with rebase or git in general yet. 我对总体上的rebase或git还是没有信心。
Remember, you can always just make a copy of your repository and try things out there without worrying about mucking things up. 请记住,您始终可以只复制存储库并在那里进行尝试,而不必担心将其存储起来。 In fact, if you are running commands you're not familiar with recommended by people you don't know, this is probably a good idea in general. 实际上,如果您正在运行不熟悉的人推荐的命令,那么通常这是个好主意。
Could you give specific commands for me to try? 您能给我一些具体的命令吗?
First, make sure you have an up-to-date copy of the remote repository: 首先,请确保您拥有远程存储库的最新副本:
git remote update
Next, make sure you are on your feature branch: 接下来,确保您在功能分支上:
git checkout myfeature
And finally, rebase
onto the updated master
branch: 最后, rebase
到更新的master
分支:
git rebase origin/master
Depending on the changes in master
since you created your feature branch you may need to perform some conflict resolution. 自创建功能分支以来,取决于master
的更改,您可能需要执行一些冲突解决方案。 If the only changes was that your feature branch was merged, you shouldn't have to correct anything. 如果唯一的更改是您的功能分支已合并,则您无需进行任何更正。
(Note that the above assumes you are working with a remote named origin
, which is common but not guaranteed.) (请注意,以上假设您使用的是远程命名origin
,这很常见,但不能保证。)
You can git stash
those changes while you create a new branch. 您可以在创建新分支时git stash
这些更改。 git checkout <<master branch name>>
then git checkout -b <<new topic branch name>>
. git checkout <<master branch name>>
然后git checkout -b <<new topic branch name>>
。
You've got a clean copy of master now, so let's get those stashed changes with git stash pop
. 您现在已经拥有一个完整的master副本,因此让我们使用git stash pop
那些隐藏的更改。 Now you're back to where you started, with all your already committed changes in the trunk and your new changes ready for commit. 现在,您回到了开始的位置,所有已提交的更改已在主干中,新的更改已准备好提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.