top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

how to revert back to the old version in Git

+1 vote
545 views

Suppose i have a directory with many files .. I commit a good version .. then I make a bunch of changes and I messed something up .. how do I revert back to the old version? will all the files be replaced from the current messed up files to the older good files? I am using SourceTree.

posted Jul 14, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

I dont use SourceTree, but I know how to you do it in command line: if you want to delete forever the changes you have done, you need to get the commit hash of the commit where you want to return (the commit before the mess). For that you can use the command git log to get the hash. With the hash, use the command git reset --hard hash-id to return your project to state, deleting all changes that were done after that commit. If you want only to undo the changes, preserving the mess changes in the history, use the command git revert hash-id.

answer Jul 14, 2013 by anonymous
I have done a little mistake: with git reset --hard hash-id, you will return to the project state of the commits hash. With that, all changes that were done after that commit will be lost.  with git revert hash-id, you will undo the changes that were done in the commits hash. So, only one commit will be undone in this case. In both cases, git will change the files t automatically.
Similar Questions
+1 vote

For a project I use git with a dev branch. If it get's stable, it is merged to master. Now I have to maintain different versions of the software. (for example v1.0 and v2.0)

What is the best way to handle a hotfix for the old version v1.0? I know, I can create a hotfix branch. But what to do after that? Should I maintain this hotfix branch forever or is it better to merge the hotfix somehow into the master branch?

Currently I have to integrate a hotfix for v1.0. It's about a feature, which was removed in v2.0. So I think it's not a good idea to merge it back to master. But is it really a good idea to maintain a long running branch for every version?

+3 votes

I opened a file and wrote a piece of code.
When I ran $git diff
it is showing the differences what I did.
Can I get back the file (version) which is in remote branch ?
Is there any command ?

+1 vote

I did commit for so many times. So how can go to a particular commit code, or previous version of my code.

+3 votes

Is there a particular reason or is it that it's just not bothered being built that often that new versions of Git is released?

How can I build new versions of Git myself?

+1 vote

I want to connect my android studio with git and installed git separately and when I enable version control. There is an error
"Cannot run program "git.exe" The system cannot find the file specified" searched in C drive programs files and X86 too but didn't get git.exe location.

...