Jennifer P.
Jennifer P.

Reputation: 387

Move git remote head to earlier commit

Can I move the head of a remote repository to an earlier commit without creating a revert commit? Meaning that after this operation there will be less commits in the remote.

Just to clarify, this is what I am not interested in:

  1. Move the head of a local repository (unless necessary for manipulating the remove). This question is about remote.
  2. Creating a new commit that reverts previous commits.

Possible or not?

Upvotes: 1

Views: 532

Answers (1)

Amber
Amber

Reputation: 527448

Sure:

git push origin <sha>:HEAD

Will set the remote repository's HEAD to point at <sha>. In general, git push can accept any sort of source:destination style refspec, so you can for instance change what arbitrary remote branches refer to as well:

git push origin master:deploy

This would set the remote deploy branch to point at the same commit as the local master branch.

Upvotes: 2

Related Questions