Home > database >  Revert to a specific commit on Gitlab
Revert to a specific commit on Gitlab

Time:05-22

I'm fairely new to git.
While working on a project on Gitlab, I made some changes in the development branch(green colored branch) instead of checking out a new branch from the development, making changes in the new branch and then merging it back to the development.
Meanwhile, one of the other developers took a pull from the development branch and started working on it(ARE-1195). Now, I know this is going to create a lot of merge conflicts when the developer will try to merge his branch into the development branch. How can I avoid this? I tried looking for a possible solution and came across two terms, revert and reset but i'm confused between these.
I want to revert my repository back to the commit where the other developer created ARE-1195 but still keep the changes I made after that.
Posting the latest git graph snippet for reference.

enter image description here

CodePudding user response:

I tried looking for a possible solution and came across two terms, revert and reset but I'm confused between these.

Your confusion is appropriate. Git's author (Linus Torvalds) unfortunately chose the wrong verb for at least one of these two actions: the one called revert should probably have been called backout (as it is in Mercurial).

To make sense of both, though, we should start with what a commit is and does for you. The image you included—which I will transform here into a new, different image—shows some of this:

       B--C--D--E   <-- ARE-1195
      /
...--A-----F----G   <-- development-ui-...

Each uppercase letter here, A through G, stands in for a commit, just as each colored dot in the original image stands in for a commit. In my drawing, the newer commits are towards the right, while in the original image, the newer commits are towards the top. So the drawings are different but they show the same thing:

  • The most recent or newest ARE-1195 commit is commit E.
  • The most recent / newest development-ui commit is commit G.

Every commit, in Git, has a unique number, but this number is huge—something between 1 and 1461501637330902918203684832716283019655932542975, right now, with future versions of Git going even higher—and seems entirely random (though it's not). It's normally expressed in The difference between reset and revert

Consider the illustration above, with a common start case on the left hand side and the two options side-by-side on the right. Pay attention to the master branch in this case, as it is what's being modified with the two commands.

Source: Above excerpt is taken from this full length post on the subject: How to Undo Changes in Git (reset vs revert vs restore)

  • Related