主控被污染,使主控干净以及与被污染的主控同步的干净分支
问题陈述:
我有2个主要分支:master(PROD) &开发(UAT)。 每当我的团队收到应用程序的更改请求时,我们都会从 master 创建一个分支来进行更改,并且在将分支合并到 master 之前,我们执行“git pull origin master”,以便我们的分支代码必须与主代码同步。
二月初,我的同事将一个分支合并到master中。但这里的分支不是从 master 创建的。所以主人就被污染了。我恢复了更改,但恢复不正确。我所做的是“git revert -m 2”。恢复提交后,master 上有 3 次合并提交。
我有最后一次提交 ID,直到 master 分支没有被污染。我主要关心的是我希望主人干净。
问题:
- 如何返回到使 master 干净的提交?
- 有一些分支与污染的主控同步。如何以 master 的恢复操作也适用于分支的方式清理 master?
提前致谢。
PS:我没有任何GUI工具。
Problem Statement:
I have 2 main branches: master(PROD) & dev(UAT).
Whenever my team receives a change request on the application, we create a branch from master do our changes, and before merging the branch into master, we do "git pull origin master", so that our branch code must be in sync with master code.
At starting of February, my colleague merged a branch into master. But here the branch was not created from master. So the master got polluted. I reverted the changes but the revert was not proper. What I did was "git revert -m 2". After the revert commit, there are 3 merge commits on master.
I have the last commit id till where the master branch was not polluted. My main concern is that I want the master to be clean.
Questions:
- How to get back to the commit which will make the master clean?
- There are branches which are in sync with polluted master. How to clean the master in such a way that reverted actions of master applies to the branch as well?
Thanks in advance.
PS: I don't have any GUI tools.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,
git revert
不会删除任何提交。这就是 git revert 的全部意义。因此,如果您抱怨合并提交仍然存在,这是正常的,您不应该抱怨它。另一方面,看来你发出了错误的命令。恢复合并提交以使传入分支对主线分支没有影响的方法是说
换句话说,当您应该说
-m 1< 时,您却说了
-m 2
/代码>。此时你有两个选择。
一种可能性是恢复坏的恢复,然后进行良好的恢复。
另一种可能性就是
重置 --hard
回到错误合并之前的状态 - 但如果这是共享材料,那么这是不受欢迎的,因为它可以让每个人别人的生活很艰难。First of all,
git revert
does not remove any commits. That is the whole point ofgit revert
. So if your complaint is that the merge commits are still there, that is normal and you should not be complaining about it.On the other hand, it looks like you gave the wrong command. The way to revert a merge commit so that the incoming branch has no effect on the mainline branch is to say
In other words, you said
-m 2
when you should have said-m 1
.You have two choices at this point.
One possibility is to revert the bad revert, and then do a good revert.
The other possibility is just to
reset --hard
back to the state of things before the bad merge(s) — but that is frowned upon if this is shared material, as it can make everyone else's life very difficult.如果您知道您想要它的优点(例如
good123
),那么在本地返回原始状态的最简单方法是:这将使您的本地
master
就好像在good123之后什么也没发生一样。如果您希望服务器(原始/主服务器)处于相同状态,那么您需要“强制推送”。这是危险的,因为它会覆盖远程状态,并迫使您的同事处理这种情况。首先确保您有备份。
团队中的任何其他人都需要为他们的工作创建一个新分支(例如
mytask2
)并与此更新的主节点重新同步。最好的方法取决于他们在“污染”状态之上做了多少工作。在最简单的情况下,他们在“污染”之前只进行了一次提交mytaskcommit123
,就是进行“挑选”:请注意,在 git 中没有单一的 master。每个开发人员都有 2 个 master 副本:
因此每个开发人员都需要更新这两个副本。在上面的脚本中,“fetch”更新远程脚本,“reset”更新本地脚本。
对于更复杂的情况,
git rebase -i
或git reset --mixed
可能会有所帮助。根据工作量,考虑保持受污染的历史记录原样,然后恢复损坏的提交。
If you know the good point where you want it to be (like
good123
), then the easiest way to come back to the pristine state locally is:This will make your local
master
as if nothing has happened after good123.If you want the server (origin/master) to be in the same state, then you'd need to "force push". This is dangerous, as it will overwrite the remote state, and force your peers to handle the situation. Make sure you have a backup first.
Any other person in the team would need to make a new branch for their work (e.g.
mytask2
) and re-sync with this updated master. The best way depends on how much work did they do on top of the "polluted" state. In the simplest case where they've had just a single commitmytaskcommit123
before "contamination" is to do a "cherry pick":Note that in git there's no single master. Each developer has 2 copies of master:
So each developer would need to update both. In the script above "fetch" updates the remote one, and "reset" updates the local one.
For more complex cases
git rebase -i
orgit reset --mixed
can be helpful.Depending on how much work is it, consider keeping the polluted history the way it is, and just reverting the broken commit.