Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I just started using Git on Windows and I have a small question. When I say git commit along with a message I realize that git commits the file. But where exactly does it store the commited file?

Let's say I make some changes and want to revert back to my third commit using Git GUI. How exactly do I do that?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Git commit only saves it to the stage, which is locally on your computer. Use Push to update it to a remote server (Like github).

Use git revert <ID> to revert back to a previous commit. each commit has an identifying code.

See here for more details on revert

share|improve this answer

The above answer is not quite correct - git revert <ID> does not set your repository to that commit -- git revert <ID> creates a new commit that undoes the changes introduced by commit <ID>. It's more or less a way to 'undo' a commit and save that undo in your history as a new commit.

If you want to set your branch to the state of a particular commit (as implied by the OP), you can use git reset <commit>, or git reset --hard <commit> The first option only updates the INDEX, leaving files in your working directory unchanged as if you had made the edits but not yet committed them. With the --hard option, it replaces the contents of your working directory with what was on <commit>.

A note of warning that git reset will alter history -- if I made several commits and then reset to the first commit, the subsequent commits will no longer be in the commit history. This can cause some serious headaches if any of those lost commits have been pushed to a public repository. Make sure you only use it to get rid of commits that haven't been pushed to another repository!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.