1

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.

Waleed Naveed
  • 2,293
  • 2
  • 29
  • 57
  • 1
    Generally, the answer is no: Visual Studio should have applied the same rules that `git pull` applies, which say that you should commit first. If you had committed, you could get your files back. Since VS didn't do this, it may be the case that VS has its own, non-Git way to recover your files, but Git itself does not. – torek Jul 26 '19 at 21:13
  • @torek That should be an answer. – Caleb Jul 30 '19 at 22:06
  • See also: [Why is Visual Studio 2017 allowing GIT pull with uncommitted changes?](https://stackoverflow.com/q/50744655/643383) – Caleb Jul 30 '19 at 22:20
  • @Caleb: I don't have or use VS, so I can't say what it *really* does, or how to configure it to do something better, if that's even possible. The `git pull` and `git merge` code *used* to allow you to merge with uncommitted changes, but that turned out to be a mistake and was outlawed in relatively-early Git. Why VS doesn't (if and when it doesn't), I can't answer. – torek Jul 30 '19 at 22:33

1 Answers1

1

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • According to my re-search and after discussing it with my seniors, i come to know that Abort in GIT will discard all the local changes, basically if you abort the merge GIT will take you back to the most recent GIT which it has @VonC – Waleed Naveed Jul 31 '19 at 05:35
  • 1
    @WaleedNaveed I agree. I have edited the answer with the relevant section of the `git merge` man page. – VonC Jul 31 '19 at 06:06