Search code examples
gitgit-merge

Git: working file is different than last commit without having any commit for the changes


I have a file where:

The previous version of the file, with commit (ABC for example) is correct however the current (working file), compared to the previous version (using gitlens on vs code), lost many changes that I want to keep.

The problem is that I want to find & revert the commit that made the wrong changes (the one that affected the working file) but the last commit I can see for the working file is (commit ABC, which is the correct version)

How do I get the commit (or merge commit) that caused the file to be in the wrong state?

Notes:

  1. My git status: nothing to commit, working tree clean

  2. I found the last commits for the file mentioned using:

    git log --follow -- full_path_to_file which show commit ABC (where the file is in the correct state)

  3. I think this might be related to a git merge with conflicts (while pulling master branch into this feature branch that I am working on) that was handled incorrectly, where someone took the the old version of the files instead of taking the updated version

Solution

  • The problem here that led to this, was running git log --follow -- full_path_to_file

    By running instead git log full_path_to_file ( instead of the above), it has shown the commit that resulted in the file (which has the incorrect/undesired state)

    By checking that merge, it was merging two changes (which both didn't have the new changes that I am missing, causing that issue)