-1

I had a weird experience with git right now, I had a commit which was done more than one week ago, I store my repository in bitbucket, if I run the git log command, I can see the commit that I did, but the actual files included in that commit were lost. This is the second time that I have experienced it, the first was when I thought I wasn't able to commit that changes and lost it accidentally, but now after checking my log those two commits exists. Any idea why this happened?

Also please note that if I checkout to that specific commit, the files will show. But when I go back to my latest commit, the files were gone. I know haven't removed those.

JCS
  • 13
  • 3
  • 1
    Perhaps you forgot to add the files to the staging area before committing? – Martin G Sep 06 '15 at 06:58
  • I agreen with @Martin, this is very common – WeeniehuahuaXD Sep 06 '15 at 06:59
  • I don't think so, if I checkout to that specific commit, the files will show. But when I go back to my latest commit, the files were gone. I know haven't removed those. – JCS Sep 06 '15 at 07:01
  • Can you try running `git log -1 --stat -- ` to see what the last commit involving that file is and include the command and the output in your question. – cyphar Sep 06 '15 at 07:04
  • @cyphar, tried your suggestion, after running that command, nothing showed. Maybe I just need to create that migration again. Thanks – JCS Sep 06 '15 at 07:12
  • Did you do this in a separate branch / have you rebased and removed that commit from your history? Can you *from the current branch you're in* see the commits that modified the file in `git log --stat`? – cyphar Sep 06 '15 at 07:15
  • @cyphar, yes I did this on a separate branch and I had never rebased or removed that commit from my history. If I run that command, I could not see any modification of that file and also I could not remember a scenario where I modified that file yet. Thanks – JCS Sep 06 '15 at 07:21

1 Answers1

0

. Maybe I just need to create that migration again

You can restore at any time (like in your current HEAD) those file with:

git checkout <acommit>-- <file_path>

See more at "Find and restore a deleted file in a Git repo".

A git log --diff-filter=D --summary helps pinpoint the commits with deleted files.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • In *extreme* situations, you can also use `git reflog`. – cyphar Sep 06 '15 at 07:21
  • @cyphar yes, when the commit is lost. But here, that doesn't seem to be the case: the commit is visible, and accessible from HEAD. – VonC Sep 06 '15 at 07:23
  • That worked, thanks @vonC, before posting this question here I already did the git reflog and tried to merge that commit to my HEAD but replied "Already up to date". Thanks for that solution by the way. – JCS Sep 06 '15 at 07:27
  • @JCS yes, if git considered the branch has "already merged", it would have answered that. The checkout is more direct. – VonC Sep 06 '15 at 07:28
  • @vonC, sorry, but I don't get it, it says "already up to date" maybe because there is no missing commit? Yet the file that I created was missing even though I haven't modified or deleted it. – JCS Sep 06 '15 at 07:31
  • @JCS so `git log --diff-filter=D --summary` returns nothing? (when done in the current branch, or from that other branch?) – VonC Sep 06 '15 at 07:32
  • @vonC, it returns my commit log, what puzzles me is that the file went missing without deleting or modifying it. I'll review my log and see where I made a mistake. Thanks a lot – JCS Sep 06 '15 at 07:38