Set older revision to be the HEAD, revert to previous state with “git push”, undo remote history

By neokrates, written on July 15, 2010

git   snippet

  • Join date: 11-30-99
  • Posts: 224
View Counter:
  • 1,035 views
Rate it
Ad
Poll
  • How would you prefer to migrate to new technology?

    View Results

    Loading ... Loading ...
Feeds:
  • bodytext bodytext bodytext

You have some status in the repository which you want “HEAD” to point to. With Git remote HEAD can be set by forcing the push command.

Such method is useful for example if you want rollback or undo your commits until some particular revision. After you done, master revision is altered.
History in the remote repository is erased as well as changes until the new HEAD revision. Anyone who makes a new clone will get the ‘new’ HEAD you just set.

⚠ If you or someone else pushes the ‘OLD’ repository state, the history will be restored. Pushing changes from the clone made after git push -f origin works OK and creates new ‘commit history’ from the point you set.

1

List avalable revisions

# git rev-list HEAD
70c5717dce2e023943cc4168dc95632a5baee6af
bc84dc5eb220a471c9a5a932fe7ef2e4501320be
fa1504a9e5b0d1e0ee6064a9b80c838dc81a8ef9
442448e186a03db5f5470ca438e69b2ee2a67f71
4b9bfe2dd388d34ba5ba4400990e69744af44fd2
6c138222515306009c35303e9a4653573875b992
daae8a1798c8d66bbe1738d177ed9075abaa94d6
5b96cb0d40b1f55a935f5c74970b72421fef6d00
e08918323e03800468e1d8de8d813ac2c1383408

2

Set new HEAD

# git push -f origin 5b96cb0d40b1f55a935f5c74970b72421fef6d00:master
Total 0 (delta 0), reused 0 (delta 0)
=> Syncing Gitorious... [OK]
To git@your.git.repo:your-project/your-repo.git
  + daae8a1...5b96cb0 5b96cb0 -> master (forced update)

3

And for any other branch

git checkout your-branch
git rev-list your-branch
// select your rev, i.e. SHA1 = 4b9bfe2dd388
git push -f origin 4b9bfe2dd388:your-branch
Be Sociable, Share!
 
Does that help to solve your problem?
VN:F [1.8.5_1061]
Rating: 0 (from 4 votes)
2 votes 'YES'  2 votes 'NO'
TAGS
No tags for this post.
RELATED
Pages
Posts
SOCIAL
Be Sociable, Share!

One Response to “Set older revision to be the HEAD, revert to previous state with “git push”, undo remote history”

  1. Javi says:

    Thanks a lot!

Leave a Reply