Skip to main content
Explain where -m sends its message
Source Link
jpaugh
  • 6.9k
  • 4
  • 42
  • 93

You can do it for arbitrary refs. This is how to move a branch pointer:

git update-ref -m "reset: Reset <branch> to <new commit>" refs/heads/<branch> <commit>

where -m adds a message to the reflog for the branch.

The general form: is

git update-ref -m "reset: Reset <branch> to <new commit>" <ref> <commit>

You can pick nits about the reflog message if you like - I believe the branch -f one is different from the reset --hard one, and this isn't exactly either of them.

You can do it for arbitrary refs. This is how to move a branch pointer:

git update-ref -m "reset: Reset <branch> to <new commit>" refs/heads/<branch> <commit>

The general form:

git update-ref -m "reset: Reset <branch> to <new commit>" <ref> <commit>

You can pick nits about the reflog message if you like - I believe the branch -f one is different from the reset --hard one, and this isn't exactly either of them.

You can do it for arbitrary refs. This is how to move a branch pointer:

git update-ref -m "reset: Reset <branch> to <new commit>" refs/heads/<branch> <commit>

where -m adds a message to the reflog for the branch.

The general form is

git update-ref -m "reset: Reset <branch> to <new commit>" <ref> <commit>

You can pick nits about the reflog message if you like - I believe the branch -f one is different from the reset --hard one, and this isn't exactly either of them.

removed the other answer.
Source Link
Bhargav Rao
  • 51.6k
  • 29
  • 124
  • 141

N.B. If you simply want to move a branch to another commit, the easiest way is

git branch -f branch-name new-tip-commit

as detailed by Chris Johnsen's answer.

You can do it for arbitrary refs. This is how to move a branch pointer:

git update-ref -m "reset: Reset <branch> to <new commit>" refs/heads/<branch> <commit>

The general form:

git update-ref -m "reset: Reset <branch> to <new commit>" <ref> <commit>

You can pick nits about the reflog message if you like - I believe the branch -f one is different from the reset --hard one, and this isn't exactly either of them.

N.B. If you simply want to move a branch to another commit, the easiest way is

git branch -f branch-name new-tip-commit

as detailed by Chris Johnsen's answer.

You can do it for arbitrary refs. This is how to move a branch pointer:

git update-ref -m "reset: Reset <branch> to <new commit>" refs/heads/<branch> <commit>

The general form:

git update-ref -m "reset: Reset <branch> to <new commit>" <ref> <commit>

You can pick nits about the reflog message if you like - I believe the branch -f one is different from the reset --hard one, and this isn't exactly either of them.

You can do it for arbitrary refs. This is how to move a branch pointer:

git update-ref -m "reset: Reset <branch> to <new commit>" refs/heads/<branch> <commit>

The general form:

git update-ref -m "reset: Reset <branch> to <new commit>" <ref> <commit>

You can pick nits about the reflog message if you like - I believe the branch -f one is different from the reset --hard one, and this isn't exactly either of them.

added link to the original answer the easiest solution came from
Source Link
CupawnTae
  • 14.5k
  • 3
  • 30
  • 60

N.B. If you simply want to move a branch to another commit, the easiest way is

git branch -f branch-name new-tip-commit

git branch -f branch-name new-tip-commit

as detailed by Chris Johnsenas detailed by Chris Johnsen's answer.

You can do it for arbitrary refs. This is how to move a branch pointer:

git update-ref -m "reset: Reset <branch> to <new commit>" refs/heads/<branch> <commit>

The general form:

git update-ref -m "reset: Reset <branch> to <new commit>" <ref> <commit>

You can pick nits about the reflog message if you like - I believe the branch -f one is different from the reset --hard one, and this isn't exactly either of them.

N.B. If you simply want to move a branch to another commit, the easiest way is

git branch -f branch-name new-tip-commit

as detailed by Chris Johnsen.

You can do it for arbitrary refs. This is how to move a branch pointer:

git update-ref -m "reset: Reset <branch> to <new commit>" refs/heads/<branch> <commit>

The general form:

git update-ref -m "reset: Reset <branch> to <new commit>" <ref> <commit>

You can pick nits about the reflog message if you like - I believe the branch -f one is different from the reset --hard one, and this isn't exactly either of them.

N.B. If you simply want to move a branch to another commit, the easiest way is

git branch -f branch-name new-tip-commit

as detailed by Chris Johnsen's answer.

You can do it for arbitrary refs. This is how to move a branch pointer:

git update-ref -m "reset: Reset <branch> to <new commit>" refs/heads/<branch> <commit>

The general form:

git update-ref -m "reset: Reset <branch> to <new commit>" <ref> <commit>

You can pick nits about the reflog message if you like - I believe the branch -f one is different from the reset --hard one, and this isn't exactly either of them.

Making the more-useful-to-almost-everybody answer much more obvious
Source Link
Leopd
  • 42.3k
  • 31
  • 132
  • 172
Loading
point the average dev to the git branch -f answer
Source Link
Adam A
  • 14.6k
  • 6
  • 32
  • 41
Loading
Fixed missing 's' in refs/heads/<branch>
Source Link
SethMMorton
  • 47.8k
  • 13
  • 69
  • 88
Loading
D'oh, an initial slash snuck in where it shouldn't have
Source Link
Esteis
  • 4.9k
  • 4
  • 30
  • 45
Loading
Put answer to question up front, general answer second.
Source Link
Esteis
  • 4.9k
  • 4
  • 30
  • 45
Loading
Make it clear that the command takes a ref name, not a branch name
Source Link
Loading
Improved formating, now it's an answerd that don't have comments restrictions.
Source Link
Loading
fixed style
Source Link
Mot
  • 29.2k
  • 24
  • 85
  • 122
Loading
Source Link
Adam A
  • 14.6k
  • 6
  • 32
  • 41
Loading
Post Made Community Wiki by Adam A