Question

I've downloaded an open source code from Git repository. Now I want to revert to a previous version. How can I do that? There is a command like: "git revert , but I don't know the hash of a version, say version 264 of the code

Best regards

Was it helpful?

Solution

git rev-list --tags --max-count=2

Would also list the last two tags SHA1. The second one would be the one you need for a git checkout to work (and revert the content of the repo to the previous label)

Once you have that SHA1, a git describe --tags xxx would translate said SHA1 into a tag label.

OTHER TIPS

cd into the git repository. Type git tag and see if the version you're looking for shows up. If it does, you're lucky. Then you can do something like this (I assume the version you're looking for shows up as v1.2.3):

git checkout v1.2.3
autoreconf # with git repos, this is often necessary before the next step
./configure
make
sudo make install

If the version didn't show up with git tag, though, then you'll need to do something like git log --oneline | more instead and look for the relevant hash id that way. If that gives you too little information, just do git log | more.

you can use gitk to explore the repository along with its history and the hashes for the versions, or for a simple output of the commit messages and the commit hash use git log.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top