2

I had personal branch tmp-work along with mainline branch and wanted to do clean resynchronized of mainline branch in my local repository. After running the command

git fetch origin && git reset --hard origin/mainline && git clean -f -d

my tmp-work branch is no longer there. It was not pushed to a remote repository. Is there any way to recover it on MacOS? I ran Mac data recover without success.

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
azmi
  • 91
  • 6
  • 4
    possible duplicate of [Can I undo a \`git clean -fdx\`?](http://stackoverflow.com/questions/6267180/can-i-undo-a-git-clean-fdx) – Larry Shatzer Aug 28 '15 at 14:46
  • 1
    Nothing here should have deleted a local branch. Possibly the [data recovery](https://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery#Data-Recovery) documentation will have some suggestions. – larsks Aug 28 '15 at 14:48
  • Was something committed on `tmp-work`? If not, did you atleast `git add` those files? If not, then you're out of luck. Git won't have those files. – Noufal Ibrahim Apr 18 '18 at 09:06

1 Answers1

-1

I can be wrong: so, important, first do a backup of your git local repository (zip/tar/copy...) !

you should find your last commit SHA1 for your working branch in tmp-work with the command:

git reflog

then try and run (until you find the good SHA1):

git checkout <SHA1>

and finally:

git reset --hard

or:

git checkout -b <new branch name>
sligor
  • 69
  • 2
  • 2
    Those files was untracked by git, you can't restore them using git commands. – neshkeev Aug 28 '15 at 15:21
  • oh, I though he commited the change to tmp-work and that he lost those commits (detached/unreachable) due to the "git reset --hard". Of course if nothing was commited then all is erased. (and tracked changes were already erased with the reset --hard) – sligor Aug 28 '15 at 15:45