[英]Revert commits made by merging of a certain branch in master
I have a branch called tempMaster and my team is continuously merging their feature branch changed on this tempmaster branch and then merging this tempmaster into master.But i found that a certain user has merged his feature branch accidentally in the tempmaster and then he also merged this tempmaster with master. 我有一个名为tempMaster的分支,我的团队不断将在tempmaster分支上更改的功能分支合并,然后将此tempmaster合并到master。但是我发现某个用户无意中将其功能分支合并到tempmaster中,然后他也将其合并了tempmaster和master。 There are multiple merge made by the user in tempmaster and then tempmaster into master. 用户在tempmaster中进行了多次合并,然后将tempmaster合并为master。 I need to revert al the changes which has been made by merging his feature branch into tempmaster and then tempmaster into master. 我需要恢复通过将他的功能分支合并到tempmaster,然后将tempmaster合并到master中所做的更改。
I can see the history by following command 我可以通过以下命令查看历史记录
git log --author=imran.zafar@bharatconnect.com --pretty=one --since=30.days
But this only show me the commit made by the user in past one month but i am not sure when he merged his feature branch for the first time.Is there any git command by which i can revert all the commit which has been generated by the merging this feature branch into master? 但这仅向我显示了用户在过去一个月中所做的提交,但我不确定他何时首次合并其功能分支。是否有任何git命令可用来还原由合并此功能分支到主人?
To revert the merged commits on master
branch by the user, you can use below steps: 要还原用户在master
分支上的合并提交,可以使用以下步骤:
Use any of the belwo commands to show the commit history as a graph, and then find the merged commits on master branch by the user. 使用任何belwo命令将提交历史记录显示为图形,然后由用户在master分支上找到合并的提交。
gitk --all
git log --oneline --decorate --graph --all
master
branch 2.在master
分支上将找到的提交从新还原为旧 Assume the commit history as below garph. 假定提交历史如下garph。 The commits F2
and F4
on feature
branch were committed by the user, the commits T3
and T4
on tempmaster
branch were the merged commits that the user merge feature
branch into tempmaster
, the commits M2
and M3
on master
branch were merged by the user. feature
分支上的提交F2
和F4
由用户提交, tempmaster
分支上的提交T3
和T4
是用户将feature
分支合并到tempmaster
中的合并提交,用户master
分支上的提交M2
和M3
由用户合并。
…---M1---M2------…-----M3---… master
/ /
…---T1---T2---T3-----…------T4 ---… tempmaster
/ / /
…-----F1---F2---…---F3---F4---… feature
So you should revert the commits M2
and M3
on master branch. 因此,您应该还原master分支上的提交M2
和M3
。
First revert the newer commit M3
by git revert -m 1 <commit id for M3>
. 首先通过git revert -m 1 <commit id for M3>
还原较新的提交M3
。 The -m 1
option means keep the changes from the first parent and revert the changes from second parent (commit T4
) on master
branch. -m 1
选项意味着保留master
分支上的第一个父级的更改并恢复第二个父级的更改(commit T4
)。 Then the commit history will be: 那么提交历史将是:
…---M1---M2------…-----M3---…---M3' master
/ /
…---T1---T2---T3-----…------T4 ---… tempmaster
/ / /
…-----F1---F2---…---F3---F4---… feature
Now the changes introduced by T4
has been reverted as commit M3'
on master branch. 现在, T4
引入的更改已还原为master分支上的commit M3'
。
Then revert the older merged commit M2
on master
branch by git revert -m 1 <commit id for M2>
. 然后通过git revert -m 1 <commit id for M2>
master
分支上较旧的合并提交M2
。 And the commit history will be: 提交历史将是:
…---M1---M2------…-----M3---…---M3'---M2' master
/ /
…---T1---T2---T3-----…------T4 ---… tempmaster
/ / /
…-----F1---F2---…---F3---F4---… feature
And the changes introduced by T3
has been reverted by the commit M2'
on master
branch. T3
引入的更改已通过master
分支上的提交M2'
恢复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.