Changing the git commit message after clicking (assuming no one pulled it out of the remote)

I made a git commit and subsequent push. I would like to change the commit message. If I understand correctly, this is impractical because someone might have pulled out of the remote repository before making such changes. What if I know no one pulled?

Is there any way to do this?

+898
source share
11 answers

Change history

If this is the last commit, you can simply do this:

git commit --amend

This calls the editor with the last commit message and allows you to edit the message. (You can use -mif you want to erase the old message and use the new one.)

Pressing

, , :

git push --force-with-lease <repository> <branch>

"+":

git push <repository> +<branch>

--force:

git push --force <repository> <branch>

.

  • - , , , . --force-with-lease , , - (

  • , Git push . "", .

/

, , , ( , ), - :

git fetch origin
git reset --hard origin/master # Loses local commits

reset --hard. , .

, --force . --force " , , ". , reflog - , ( ).

, , --force... .

--force-with-lease .

+1280

:

git commit --amend -m "New commit message"

git push --force
+404

, :

1: git rebase -i HEAD~n n. ( , 3, , git rebase -i HEAD~3)

git , : # r, reword = use commit, but edit the commit message, , .

2: pick r , . , . . .

3: Git , r . , , .

4: . git push -f, .

+212

:

git commit --amend -m "new commit message"

,

git push -f

:)

+41

, , push --force mutiple refs, . , git push . , , . git:

, -force refs, , , push.default, , . *. push ( , ). , + refspec (, git + , ).

+18

, , rebase, , Github

+11

1.

git commit --amend -m "New and correct message"

2.

git push origin --force
+9
git commit --amend

.

git push --force-with-lease
+4

- " " ( push), , - . - , - , readme git --allow-empty. , , , , ( amend , , ). ). , . , git , () , ( ) - , . :

$ git log
commit 0c28141c68adae276840f17ccd4766542c33cf1d
Author: First Last 
Date:   Wed Aug 8 15:55:52 2018 -0600

    Errata commit:
    This commit has no substantive code change.
    This commit is provided only to document a correction to a previous commit message.
    This pertains to commit object e083a7abd8deb5776cb304fa13731a4182a24be1
    Original incorrect commit message:
        Changed background color to red
    Correction (*change highlighted*):
        Changed background color to *blue*

commit 032d0ff0601bff79bdef3c6f0a02ebfa061c4ad4
Author: First Last 
Date:   Wed Aug 8 15:43:16 2018 -0600

    Some interim commit message

commit e083a7abd8deb5776cb304fa13731a4182a24be1
Author: First Last 
Date:   Wed Aug 8 13:31:32 2018 -0600

    Changed background color to red
+2

,

git checkout origin/branchname

, pull rebase

git pull

git -c core.quotepath=false fetch origin --progress --prune

git commit --amend -m "Your message here"

,

git commit --amend

, .

git config --global core.editor your_preffered_editor_here

, , ,

git push --force

+1

, bitbucket

git commit --amend

git push --force <repository> <branch>

--force push

git ftp push --force

.

--force

bitbucket

0

All Articles