How can I change the git message of my 1 push in github? -
my environment:
i working team on github private repository.
we have master branch.
reproduce problem:
i made change (i talking single , not muilticase) , add+commit+push github private repository.
i saw message in github after push - , have mistake want change.
how can change message of push?
edit: important me no history left of mistaken message.
edit2: files pushed in github repository , not in local repository
tl;dr
git commit -v --amend git push -f
this allow edit last commit message, , replace commit on remote edits.
however
you better off pushing correction.
the way change existing commit is:
git add changed # example, add changed commit git commit -v --amend # launch editor, edit commit message
that allow edit last commit (either contents, or commit message)
you'll find can't push remote, when try it'll rejected warning this:
! [rejected] master -> master (non-fast-forward) error: failed push refs 'git@github.com:xxx/xxx.git' prevent losing history, non-fast-forward updates rejected merge remote changes (e.g. 'git pull') before pushing again. see 'note fast-forwards' section of 'git push --help' details.
which gives 2 options:
- pull first, before pushing again
- force-push (
git push -f
)
if pull first - put un-edited commit in history, it'll still exist, you'll have no problems pushing remote branch. original commit show in history merge.
if force-push, literally forcing remote branch accept local history , overwriting remote branch's history.
the note git's own perhaps best used describe why forcing push bad idea:
usually, command refuses update remote ref not ancestor of local ref used overwrite it. flag disables check. this can cause remote repository lose commits; use care.
in context, "lost commits" old version of commit edited - include changes colleague pushes in-between first push, , forced-push. reason it's risky manoeuvre.
if need it can done - either act (so nobody downloads borked-commit) or know cause problems other developer pulling , pushing branch.
Comments
Post a Comment