git reset commit and push issue

177 Views Asked by At

Recently it happened in my team that a fresher tried to do a git pull. Some conflicts appeared on the system after which the developer simply did a git reset (bringing the index to last HEAD). Then the developer "committed" one file change and pushed it to remote. Naturally quite a lot of changes were lost.

However it took us quite some time to figure out who did the bad change (and which commit was bad commit) and recovering it was a whole lot of different effort. Now in the git history (using gitk or git log) git only shows what files have been committed but this is case of overwriting previous files (I know this concept is more of CVS not git in which case files have been moved to a previous commit). What is the best strategy to debug in this case?

Once we know which branch is offending one, once I do a git diff between good and bad commit I can see list of files but looking at the particular commit only, can we find out what files have been moved to a previous commit.

Apologies if the problem is not entirely clarified.

1

There are 1 best solutions below

0
On

Take a look at the output of git log -p branch-in-question and you will see changes made, file by file. You can now act accordingly by doing git checkout <some commit> -- some files to get the branch straight again. Add all the changes and commit and push. You should be good from here on.