Home > Net >  Does reverting a specific commit from the original branch impact the integration branch?
Does reverting a specific commit from the original branch impact the integration branch?

Time:01-14

I have a branch called devbranch and a branch master. If I cherry picked a commit XYZ from devbranch to master branch, and then I revert or reset the XYZ commit from the devbranch, would that revert or reset impact, revert or rest commit XYZ from the master branch?

CodePudding user response:

A quick review of some key concepts:

  • A git repository is made up of commits.
  • Each commit contains a snapshot of all your files, and some metadata including zero or more (but normally one or two) links to parent commits.
  • History is examined by working backwards from a known commit to its parents.
  • A branch is just a pointer to a commit, giving you somewhere you can look at history backwards from.

Now some specifics:

  • git cherry-pick looks at a commit, compares it to its parent, and then reproduces the same changes somewhere else as a new commit. The new commit is not related to the original in any way.
  • git revert does the same thing, but "in reverse": it compares a commit to its parent, and then applies the opposite of that change. Again, it creates a brand new commit, which is not related to the original.

So, to come back to your question:

  • You have two independent commits - the original commit, "XYZ" which you committed on "devbranch"; and a different commit created when you cherry picked onto "master"
  • When you run git revert, you will create a third commit, undoing the changes of "XYZ"

As an alternative, you can "rewrite history", which actually means creating a new history (I like to think of it like going into a parallel universe). For instance, you could use an "interactive rebase" to replay all the commits except for the one you want to "erase from history".

CodePudding user response:

Reverting a commit simply creates an opposite commit on the current branch. It doesn't affect other branches. You'll need to revert the cherry-pick commit on the master branch as well, or you can cherry-pick the reversion commit from the dev branch. It's all the same with respect to the outcome, but it depends on how you want your history recorded.

  •  Tags:  
  • Related