Search code examples
gitgit-mergemerge-conflict-resolution

Local changes lost after aborting merge in GIT


I am working on visual studio and using git. I lost all my local changes after aborting commit. The steps which i did are:

  1. Pulled the branch using "Pull" option, had some conflicts.
  2. Manually resolved the conflicts and accepted the merge.
  3. Merge process got stuck (i do not know why).
  4. Aborted the merge process. At this point i had all my local changes in pending changes tab.
  5. I closed the visual studio and re-opened the solution, now all the local changes are lost.

Is there any way that i can get my changes back. I googled but didn't find anything useful.


Solution

  • That is why, before pulling, I always prefer to do a commit, just to be safe.

    To be on the same side (unless you are on Mac with Time Machine activated), you can install the plugin local-history: it will save for you a state of each modified file.

    Regarding git merge --abort, the man page does mention:

    The second syntax ("git merge --abort") can only be run after the merge has resulted in conflicts.
    git merge --abort will abort the merge process and try to reconstruct the pre-merge state.

    However, if there were uncommitted changes when the merge started (and especially if those changes were further modified after the merge was started), git merge --abort will in some cases be unable to reconstruct the original (pre-merge) changes.

    Therefore:

    Warning: Running git merge with non-trivial uncommitted changes is discouraged: while possible, it may leave you in a state that is hard to back out of in the case of a conflict.