0

We have a problem with git. We made some local changes and tried to commit and push. It got committed but not pushed because of some conflicts. so we took backup of conflicted files but missed to take backup of un-conflicted files which are committed. Then to resolve conflicts easily I reset it with:

git fetch origin
git reset --hard origin/master

with this the files were replaced with those in server.

My question is is there any way to get back the replaced files?

raina77ow
  • 103,633
  • 15
  • 192
  • 229
Harikrishnan
  • 3,664
  • 7
  • 48
  • 77

1 Answers1

2

If you actually committed you should be able to find the commit in using git reflog. It is very difficult to lose commits. The default setting is to preserve logs for 30 days for unreferenced commits. Therefore, there is no need to constantly make backups before trying something that might not work out. If you do not like it find what you want with the reflog.

Joseph K. Strauss
  • 4,683
  • 1
  • 23
  • 40
  • The default is not 30 days, it’s two weeks (see [`--prune` in `man git-gc`](http://git-scm.com/docs/git-gc). Note that cleanup only happens when `git-gc` is run, which may not have happened for more than 2 weeks. – Andrew Marshall Dec 23 '14 at 14:36
  • @AndrewMarshall Please read the [man page](http://git-scm.com/docs/git-gc) more carefully. The 2 weeks is for loose objects, but if a commit is referenced in the reflog it is **not** loose. The reflog is not expired for 30 days for unreachable commits. This is explicitly mentioned a few lines below with regard to the `gc.reflogExpireUnreachable` configuration setting. – Joseph K. Strauss Dec 23 '14 at 14:44
  • @AndrewMarshall `git prune` works off `git fsck --unreachable`, and fsck by default checks the reflogs. – jthill Dec 23 '14 at 14:44