Fixing invalid comment / branch name in GIT
Wed, 14 Sep 2011 22:35:33 +0000
Recently I was asked to help with fixing branch that had:
- invalid name (wrong artifact number)
- invalid comment inside (also based on wrong artifact number)
it was a mistake and programmer wanted to preserve changes done on branch, but using different name.
The solution I proposed was to:
- clone existing branch under different name
- "amend" last commit on this new branch (to fix comment)
- push new branch into correct location
- drop old branch
Sequence of GIT commands was:
$ git branch corect-name origin/invalid-name (We saved desired SHA with new name) $ git checkout corect-name $ git commit --amend (Fix comment of last commit in editor) $ git push origin corect-name (Fixed branch published on our default remote) $ git push origin :invalid-name (Weird GIT syntax for deleting remote branches)