2
  • I made an empty private repository called "clonedRepo" .

  • Then I cloned the empty repository locally on my machine under the folder htdocs.

  • Then I dragged a folder called "codebase" that had all the code under the cloned empty repo "clonedRepo".

  • Then I used the Github app for Mac OS X to commit and push all the code under the folder "codebase" to "clonedRepo" but the commit failed because a couple of video files were too large which is fair enough.

  • I clicked the undo commit button.

  • But all of a sudden all the files under "codebase" were gone. The directories remain but the files are gone.

  • I tried "git stash list" for this local repo in the terminal but that just returns the default command prompt.

I didn't have backup of this code and its really important to me because I've been working on this since weeks but making it again from scratch will be time-consuming and mundane. Any idea how I could get it back? I didn't delete the local cloned repo or anything inside it. The local repo displays itself as being worth 302 MB but contains visible stuff worth only 46KB. Please help.

bitoiu
  • 6,893
  • 5
  • 38
  • 60
C A
  • 87
  • 1
  • 8
  • 1
    undo commit wouldn't have deleted any files. Are you sure you did not run a `revert` or `reset`? What happens if you type `git reflog` can you paste the result of that command? – bitoiu Jul 30 '15 at 12:42
  • Also try: https://github.com/blog/2019-how-to-undo-almost-anything-with-git – bitoiu Jul 30 '15 at 12:42
  • look under your .git folder, this is what taking all your space. Then you can look at this [answer](http://stackoverflow.com/questions/6545232/recovering-files-from-git-objects) to try to recover from your object directory – Frederic Henri Jul 30 '15 at 13:03
  • @bitoiu This is the output from git reflog : 46e2eb0 HEAD@{0}: reset: moving to 46e2eb01205202cb31e95be55aa1108ba61b2639 c1710f2 HEAD@{1}: reset: moving to c1710f200b0265136d0997d3820b36b9fe7a68a1 3af2dc6 HEAD@{2}: revert: Revert "All-to-date" c1710f2 HEAD@{3}: commit: All-to-date 46e2eb0 HEAD@{4}: clone: from https://github.com/chaitanyaagrawal/ucl-summer-research-internship.git – C A Jul 30 '15 at 13:06
  • `HEAD@{2}: revert: Revert "All-to-date" c1710f2 ` Suspicious. You can try doing `git reset --soft 46e2eb0` and see if that helps. That is the state before the revert. – bitoiu Jul 30 '15 at 13:09
  • @bitoiu Tried doing git reset --soft 46e2eb0 but nothing changed. I am going to try Fredric Henri's answer in the meantime. – C A Jul 30 '15 at 13:11
  • 2
    What would you expect? You clicked "undo commit" and the changes of this commit (adding your files) were undone. This is exactly how things should work. To recover: `git log --oneline` --> search for the hash of the commit that introduced your codebase-files --> `git reset --hard `. Done – eckes Jul 30 '15 at 13:44

1 Answers1

2

First of all I would like to thank @bitoiu , @Fredric & @eckes for their help.

  • So basically when I added my codebase to an empty repository and committed, the commit couldn't be pushed because a video file in the codebase was larger than 100MB. On pressing "Undo the commit" I believed I lost all the codebase.

  • But actually what happened was it moved to a hidden .git folder
    within the repository.

  • To show hidden files under your repository, see this link : http://ianlunn.co.uk/articles/quickly-showhide-hidden-files-mac-os-x-mavericks/

  • Then type git reflog to get present and past hash codes of the HEAD.

  • Then type git reset --hard <hash code of the commit that introduced the files> to populate all the missing files under your
    repository.More info about git reset and on the use of --hard can be found here : Whats the difference between git reset --mixed, --soft, and --hard? .

Community
  • 1
  • 1
C A
  • 87
  • 1
  • 8