Soroush Karimi
Soroush Karimi

Reputation: 11

Undoing Git Branch Commit and Merge

I'm currently working on an assignment where we work on a local repository and push to a remote repository when we are done. We are expected to make use of branches, wherein we make all our commits before merging it into our master branch, so no commits directly to the master branch.

Everything was going fine, but I've come across a problem when I made some commits on a branch, then merged that branch into my master, before going back to the before-mentioned branch to make some more changes, committing them and merging it once again back into my master branch.

My network tree is currently looking like this: network branch

The problem being the green branch that is branching off at the end with hash 2bbbd0c.

I'm essentially looking to undo that commit completely and simply have my branch merge into my master, so my network branch shows that nothing is branching off.

One idea I have is to use git reset –hard 2b32611 (which is the hash for my latest commit on the branch before merging it into my master): enter image description here

And then to use git push -f origin 2b32611:cookies-user-tracking to push the commit and the branch, but once again I’m not sure if that’ll work, and I don’t want to mess anything up.

Upvotes: 1

Views: 40

Answers (1)

VonC
VonC

Reputation: 1324258

The git reset --hard will indeed reset cookies-user-tracking to the right commit (before merge)

All you need to do then is to force push the branch:

git push -f origin cookies-user-tracking 

Upvotes: 1

Related Questions