If i remove a commit from one branch, will that same commit be removed from the other?

3363 views git
3

Somehow, I made a commit to the master branch and a different branch.
So the exact same commit ID is present for my master branch and the other branch.

I already created the pull request on the other branch to apply the changes to the upstream repo. (The pull request is not yet approved).

The problem is that I just found out that again, the same commit made in that PR is on my master branch. I figured that out after I made a new branch off of master and made a new commit for a different PR.
So now when attempting to make a new PR for this new branch, it includes the commit that was on the master since I made the branch off of master.

I want to know that if I delete the commit off of master branch, will it effect the commit made on the other branch that is in my active PR?
(because they are referenced to by the same commit ID)

answered question

No it won 't. Commits are local. Branches are separate in remote.

1 Answer

2

I want to know that if I delete the commit off of master branch, will it effect the commit made on the other branch that is in my active PR?

No it will not:

  • deletion of a commit (for instance through a git reset --hard @~) is a local operation
  • the commit isn't really "deleted", master HEAD simply points to its previous commit, assuming your was the most recent on master branch
  • even if you force push your master branch (and publish your deletion), that won't affect the remote PR branch

posted this

Have an answer?

JD

Please login first before posting an answer.