简体   繁体   English

已经与master合并的分支中的错误如何解决?

[英]How to fix a bug in a branch after it has already been merged with master?

Below is my current process. 以下是我目前的流程。 The idea is stable master. 这个想法是稳定的主人。 We make our changes on our own branches and then merge with master. 我们在自己的分支机构上进行更改,然后与master合并。

  • git checkout -b branch-name git checkout -b分支名称
  • git push origin branch-name git push origin分支名称
  • make my changes 做我的改变
  • git add . git添加
  • remove unnecessary changes with git checkout HEAD — path-to-file 使用git checkout HEAD删除不必要的更改—文件路径
  • git commit -m “commit message” git commit -m“提交消息”
  • git push origin branch-name git push origin分支名称
  • git checkout master git checkout主
  • git pull origin master git pull起源大师
  • git merge branch-name git merge分支名称
  • git push origin master git push origin master
  • if I then notice a bug in my code, I just use the same branch to fix the problem, and re-merge with master 如果我随后在代码中发现错误,则只需使用同一分支来解决问题,然后与master重新合并

Does this seem correct to you? 这对您来说是否正确? Is there a better flow? 有更好的流程吗?

Thank you. 谢谢。

Yes, You can fix your bugs in your branch . 是的,您可以在分支机构中修复您的错误。 Then add, commit, push and merge with master. 然后添加,提交,推送并与master合并。

$ git checkout <branch-name>

Fix bugs here

$ git commit -am 'Fix bugs'        # add and commit
$ git push origin HEAD             

$ git checkout master
$ git pull origin master
$ git pull origin <branch-name>
$ git push origin HEAD            

You can do changes on your branch and merge them to master again, but as I can see you have already pushed both master and your branch to remote repository. 您可以在分支上进行更改,然后再次将其合并为master,但是正如我所见,您已经将master和分支都推送到了远程存储库中。 Remember that you should not amend commits already pushed to the remote, so you cannot use git commit -a ! 请记住,您不应该修改已经推送到远程的提交,因此您不能使用git commit -a

Maybe easier and cleanier way to do it would be to fix changes on your branch and then cherrypick just this one commit with fixes. 也许更简单,更干净的方法是修复分支上的更改,然后仅对这一提交进行修复。 It would look like this (assuming you are on master right now) 看起来像这样(假设您现在是主人)

$ git checkout <branch-name>

fix bugs

$ git commit -m "fixes"
$ git push origin <branch-name>
$ git log

from git log get the commit Id , it would look like this: 从git log获取提交ID ,它看起来像这样:

commit 4cc1c6ec2d5dc2ce21557681c9abddced1a56645
Author: your name <e-mail>
Date:   Wed Nov 30 10:51:45 2016 +0100
commit message

Now copy commit ID and use it co move fixes to master 现在复制提交ID并将其用于共同修复

$ git checkout master
$ git cherry-pick 4cc1c6ec2d5dc2ce21557681c9abddced1a56645
$ git push origin master

This way you will have the same commit with fixes on both master and your branch. 这样,您将对master和您的分支进行相同的提交和修复。

暂无
暂无

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

相关问题 我如何知道一个分支是否已经合并到 master 中? - How can I know if a branch has been already merged into master? Git:如何删除已经提交,推送并合并到master的分支? - Git: How do I remove a branch that has already been committed, pushed, and merged into master? 分支合并到 master 后的 git rebase - git rebase after branch has been merged into master 如何检查master是否已合并到当前分支 - How do I check if master has been merged into current branch 在子分支已合并回master之后,VSTS Git将孙分支合并到master - VSTS Git merge grandchild branch into master after child branch has been merged back into master 如何重做已经合并到另一个分支中的提交 - How to rework a commit that has already been merged in an another branch 重新设置已经合并的分支 - Rebase a branch that has already been merged 如果其他分支已合并到主分支,如何将我的分支合并到主分支 - How to merge my branch to master if some other branch has been merged into the master 问题将Git Feature分支合并到“Beta”分支(在它已经合并到“Develop”分支之后) - Issue merging Git Feature branch into “Beta” branch (after it has already been merged to “Develop” branch) 处理向功能添加新迷你功能的正确方法,哪个分支已合并到主服务器中 - The right way to handle adding new mini-features to a feature, which branch has already been merged into master
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM