Rombo
Rombo

Reputation: 361

Revert files to a specific commit without affecting local repository git

This is what I'm doing:

git init         // initialize repository
git add foo.bar  // adds foo.bar to the repository
git commit -m "commit message"  // commits the added files
git status  // status of repository
git log     // commit log

How to revert files to a specific commit without affecting repository? Simple use case scenario: you want to test how the program works with an older revision but keeping in the repo the later commits.

Commits id is a sha key? no number like svn?

Upvotes: 0

Views: 636

Answers (2)

michas
michas

Reputation: 26555

  • You use git commit to add new commits.
  • You use git log to list all commits (this will also show the SHA1 id of the commits)
  • You use git reset --hard <SHA1> to reset your branch to a given SHA1 id
  • You use git checkout <SHA1> to view an older commit without changing your branches.

Git has a great help. For example you can use git help reset for details about git reset.

Use gitk --all or git log --graph --decorate --all for a good overview over the current situation.

Upvotes: 1

Mart&#237;n Schonaker
Mart&#237;n Schonaker

Reputation: 7305

You can reset the last commit through: git reset HEAD~1.

Yes, git uses SHA1 hashes for commit IDs.

Upvotes: 1

Related Questions