Reputation: 729
I've inherited a project from aonther programmer and it once have source-controlled by GIT. No I've been working on the project for more than a year and jist wanted to connect it to GIT again to have some kind of revision control and somehow it started by reverting all my source code to this year-old version.
Is there ANY way I can recover my latest files to before I enabled GIT?
[edit] as requested :
git stash list
outputs :
stash@{0}: WIP on master: 4dc75b5 f<C3><B8>r refactor
stash@{1}: WIP on master: 4dc75b5 f<C3><B8>r refactor
git reflog
outputs :
4dc75b5 (HEAD -> master) HEAD@{0}: reset: moving to HEAD
4dc75b5 (HEAD -> master) HEAD@{1}: reset: moving to HEAD
4dc75b5 (HEAD -> master) HEAD@{2}: commit: f<C3><B8>r refactor
b0a5b55 HEAD@{3}: commit: First publish
6119f77 (origin/master) HEAD@{4}: commit (initial): Add .gitignore and .gitattributes.
Upvotes: 0
Views: 49
Reputation: 51988
Inspect your stash, and the reflog : those are two places where git may store files without referencing them from a commit.
# go to the directory of your project
$ cd path/to/project
# to view if anything is stashed away :
$ git stash list
# to view the reflog :
$ git reflog
It looks like you have some changes stashed away (git stash list
mentions two lines).
You can view the content of those stashes :
# to view the content of the latest stash :
$ git stash show # view the list of files stored in the first stash
$ git stash show -p # view the complete diff (-p for 'patch') of the first stash
# to view the content of stash@{1} (the second stash) :
$ git stash show stash@{1}
$ git stash show -p stash@{1}
# obviously : if you have more stashes, you can inspect them using 'stash@{n}',
# 'stash@{0}' if also a valid way to target the latest stash
You can also restore a stash on disk :
git stash apply # apply stash@{0}
git stash apply stash@{n} # apply stash@{n}
As always : git help
is your friend, run git help stash
for more details on how to navigate and restore stashes.
Once you have restored your files : do store them in a commit
git add the/files you/want to/commit
# some shortcuts :
git add -u # add all files that are already tracked by git
git add -A # add all files you have on disk
git commit
# if you have a remote repo : push that commit to the remote
git push # push your current branch to its remote counterpart (if it has any)
git push origin HEAD:hclausen/backup # create a remote branch on the fly
Upvotes: 1