I am new to git and github and I have some trouble.
I am using github for windows to manage a small project I have. I think I’ve lost some changes I recently did to my code. What I did was:
- Changed some files.
- Accidentally committed the changes.
- Reverted the commit.
- Then I pressed “roll back to this commit”.
Now all changes are gone, including some new files I added. Can I save them? I have also installed git (command line) so I can execute any command you think will help.
One of the nice things about git is that it’s REALLY hard to lose anything, unless you’re doing something weird.
What you need to do is to find the point which represents the state at which you want to be.
Let’s say you examine git log and determine that hash 01dbc4… is the point in time to which you want to return. To do so, simply do:
Note that if you have uncommitted changes, you’ll need to stash them first.
Now, if that commit is missing the extra files you want and they’re in a later commit, it gets a bit more complicated. But what you can do is set your master branch to the point from which you want to start, and then set a branch to the point which has the new files. You can then copy or or selectively merge the missing information from the new branch to your master branch, making your master branch look how you want it.
Note that even if you move a branch’s pointer around like when using git reset –hard above and orphaned later commits, you get them back by examining
git reflogand reseting to them, or creating a branch that points to them.