This question already has an answer here:
In this article, you will learn how to hard/factory reset Galaxy devices in 3 main scenarios, as well as a 1-click tool to do samsung hard reset. Download Download Samsung, the second biggest mobile manufacturing company in the world, have launched quite a few handsets for their highly popular “Galaxy” series.
- How do I revert a Git repository to a previous commit? 41 answers
I know that Git tracks changes I make to my application, and it holds on to them until I commit the changes, but here's where I'm hung up:
When I want to revert to a previous commit I use:
And Git returns:
How do I then revert the files on my hard drive back to that previous commit?
My next steps were:
But none of the files have changed on my hard drive...
What am I doing right/wrong?
PeeHaa51k4343 gold badges171171 silver badges245245 bronze badges
Brian McDonoughBrian McDonough4,72644 gold badges1414 silver badges2222 bronze badges
marked as duplicate by user456814 Jul 22 '14 at 3:33
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2 Answers
First, it's always worth noting that
git reset --hard
is a potentially dangerous command, since it throws away all your uncommitted changes. For safety, you should always check that the output of git status
is clean (that is, empty) before using it.Initially you say the following:
So I know that Git tracks changes I make to my application, and it holds on to them until I commit the changes, but here's where I'm hung up:
That's incorrect. Git only records the state of the files when you stage them (with
git add
) or when you create a commit. Once you've created a commit which has your project files in a particular state, they're very safe, but until then Git's not really 'tracking changes' to your files. (for example, even if you do git add
to stage a new version of the file, that overwrites the previously staged version of that file in the staging area.)In your question you then go on to ask the following:
When I want to revert to a previous commit I use: git reset --hard HEAD And git returns: HEAD is now at 820f417 micro
How do I then revert the files on my hard drive back to that previous commit?
If you do
git reset --hard <SOME-COMMIT>
then Git will:- Make your current branch (typically
master
) back to point at<SOME-COMMIT>
. - Then make the files in your working tree and the index ('staging area') the same as the versions committed in
<SOME-COMMIT>
.
HEAD
points to your current branch (or current commit), so all that git reset --hard HEAD
will do is to throw away any uncommitted changes you have.So, suppose the good commit that you want to go back to is
f414f31
. (You can find that via git log
or any history browser.) You then have a few different options depending on exactly what you want to do:- Change your current branch to point to the older commit instead. You could do that with
git reset --hard f414f31
. However, this is rewriting the history of your branch, so you should avoid it if you've shared this branch with anyone. Also, the commits you did afterf414f31
will no longer be in the history of yourmaster
branch. - Create a new commit that represents exactly the same state of the project as
f414f31
, but just adds that on to the history, so you don't lose any history. You can do that using the steps suggested in this answer - something like:
11.6k88 gold badges6565 silver badges132132 bronze badges
Mark LongairMark Longair306k6262 gold badges361361 silver badges304304 bronze badges
WARNING:
git clean -f
will remove untracked files, meaning they're gone for good since they aren't stored in the repository. Make sure you really want to remove all untracked files before doing this.Try this and see
git clean -f
. git reset --hard
will not remove untracked files, where as git-clean
will remove any files from the tracked root directory that are not under Git tracking.Alternatively, as @Paul Betts said, you can do this (beware though - that removes all ignored files too)
git clean -df
git clean -xdf
CAUTION! This will also delete ignored files
25.1k1414 gold badges6161 silver badges8181 bronze badges
udayuday6,96244 gold badges2424 silver badges4949 bronze badges