Search code examples
gitversion-controlgit-mergegit-reset

Deleting commits from a branch in which other branchs are merged


I have three branches - A(branch I am working on), B, C.

The commit history of branches B and C looks like this

Branch B

  • commit b2
  • commit b1

Branch C

  • commit c2

  • commit c1

I have merged these branches into Branch A, So commit history for A looks like this

  • commit a2
  • commit c2
  • commit c1
  • commit b2
  • commit b1
  • commit a1

I want to reset my branch A to commit a1 using git reset --hard a1. If I do this does commit b1,b2 and c1, c2 gets removed from branches B and C as well or they get removed from only branch A?


Solution

  • A hard reset on Branch A will affect only that branch. The the other branches will remain unaffected.

    To answer your question - After a hard reset of Branch A with (git reset --hard a1), the commits b1 and b2 will remain in Branch B and the commits c1 and c2 will remain in Branch C.