2

I had a bit of a gaff and swapped to the completely wrong branch, pulled, and then merged our dev branch to get everything up to date. Turns out, the branch I switched to hadn't been touched in several months, and was worked on by a developer who's name I don't know and who no longer works at the company.

Given that I merged our dev branch, when I do a git log, I see allllll of the commits from everyone. So I have no idea what the last commit made on this branch was. Is there a way to see only the commits done on the my_feature branch I'm currently on?

The goal is to undo all the damage I've done and roll it back to the state it was in when I found it.

Edit:

Added answer below.

user3308774
  • 1,354
  • 4
  • 16
  • 20

3 Answers3

0

After a bit of looking I found this question which showed how to display the branch information in the git log

git log --graph --all --decorate

With that information, it is as simple as scrolling back through the logs until you find the first commit referencing the branch that was merged incorrectly.

Copy the commit hash and then you can reset everything via

git reset --hard {commit hash}
Community
  • 1
  • 1
user3308774
  • 1,354
  • 4
  • 16
  • 20
0

For operations that move HEAD in exciting ways, including merges, the previous position of HEAD is recorded in ORIG_HEAD. This makes it easy to get back to the state things were in just before you merged the other branch into my_feature:

git reset --merge ORIG_HEAD

There are a few other similar special symbolic references that Git maintains at various points. Take a look at the gitrevisions man page.

Thomas Foster
  • 301
  • 1
  • 4
0

It sounds like what you want is track the commit history down only one parent of the merge commit. If you are on a feature branch and you want to see only the commits for that feature, do

git log --first-parent my_feature
Justin Howard
  • 5,504
  • 1
  • 21
  • 48