Our project uses GitLab for code management, and when I upgraded the system to SpringBoot 2.0, the branch was merged to the Master branch. During the actual deployment, I found that a child dependency of a two-party package that I depended on had not been upgraded, causing a service to fail to drop through. Since it took time to fix the bipartite package, we decided to Revert the Master branch in order not to affect the subsequent release of other features.
The next day, after fixing the bipartite package issue, I resubmitted the Merge request, only to find that the only changes committed were to the bipartite package, and no other code changes were made.
Problem recurrence
The following mockup replicates the problem. I created a brand new project. The first commit was made in the Master branch and the commit read
|
|
Then a new branch is created dev
and the following is appended to the commit:
|
|
merge
the dev
branch to the master
branch, whereupon the master
branch will look like this.
At this point, I think the dev
branch is not finished yet, so I want to revert
it and recommit it. So find the Merge
request in GitLab
and click the Revert
button, as shown below.
Clicking Revert
is equivalent to Revert
the code to a new branch and Merge
that new branch to the Master
. The Commit
record is shown below, where revert-f8856e36
is the revert
branch.
Switch to the Master
branch after Revert
and find that the code has indeed been rolled back.
At this point, switch to the dev
branch and fill in another line at the end, which reads
|
|
Then re-initiate the Merge
to Master
request for the dev
branch.
But I found that the difference between dev
branch and master
branch commit
is only the commit record after dev
branch revert
.
When I go to the Changes
page, I see that the changes are only recorded after revert
. The line Second Commit From Dev
before revert
is not considered a change and is considered to exist on the Master
branch?
The above completes the reproduction of the problem, the Second Commit From Dev
line is lost, to be precise, the dev
branch revert
before the content is lost.
Solutions
The solution was obtained by referring to this article.
The core idea is to revert
the commit record of revert
again, so let’s start experimenting.
First switch to the Master
branch and pull out a branch revert_tmp
based on the Master
branch, this branch is used to save the commit records of revert revert
.
|
|
Find that commit record of revert
, note that there will be two records related to revert
, the first one is revert
and the second one is the record of merge
after revert
, here take the first one, as shown in the figure below.
Then switch back to the dev
branch and merge
the branch revert_tmp
to the dev
branch.
After pushing the dev
branch to the remote, we recommit the merge
request to the master
. We find that the commit record before revert
has not been retrieved, i.e. the second commit by dev
record has not been retrieved, as shown below.
This is due to the feature of revert
, although this commit record is not recovered, the code before revert
is back, as shown below.
Reference https://jitwxs.cn/38727be2.html