简体   繁体   中英

Rename commit message in GitHub

*commit N+20 <-- (HEAD)branch fb/abc(i made 20 commits in this branch)   [most recent]
.
.
*commit N <-- branch dev-abc, origin/dev-abc //created another feature branch from here "fb/abc"
.
.

then I ran the following commands:

git checkout dev-abc
get merge fb/abc

No other changes were made to the dev-abc branch. So this was a simple fast forward merge.

At this point, the graph looks like this.

 *commit N+20 <-- branch fb/abc, dev-abc(HEAD)  [most recent]
 .
 .
 *commit N <-- origin/dev-abc
 .
 .

Now, I pushed all these changes to remote

At this point, while creating a Pull Request, I got a merge conflict in one of the files. (WHY??)

Anyway, I resolved all the conflicts in the GitHub conflict resolver itself. This created a new commit in GitHub which is not present in my local copy. I need to change the commit message for this commit. How can I do this?

There is one more thing, I made two additional commits locally which I haven't pushed yet. Whenever I try to push, I get an error message saying, I have some changes in remote which are not present locally. It suggests me to git pull those changes first(I think it is the additional commit that was created on the GitHub(whose message I want to change)).

 *commit N+22 <-- branch dev-abc(HEAD)  [most recent] // how the graph appears locally
 *commit N+21

 *commit N+20 <-- branch fb/abc, origin/dev-abc
 .
 .
 *commit N <-- origin/dev-abc
 .
 .

I also have some changes which are not committed yet. They are not even in the staging area.

What is the correct sequence of steps that I should take? So, I don't lose any of my work and change the commit message too?

The git commit --amend command allows you to change the most recent commit message.

I'll explain to you how to rename both pushed and unpushed commit.

For pushed commit: Navigate to the repository.

Amend the message of the latest pushed commit:

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

Force push to update the history of the remote repository:

git push --force branch-name

Navigate to the repository directory in your terminal.

Run the following command to amend (change) the message of the latest commit:

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

What the command does is overwriting the most recent commit with the new one.

The -m option allows you to write the new message on the command line without opening an editor session.

Before changing the commit message you can also add other changes you previously forgot with:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM