Summary of Git commit log modification methods

Summary of Git commit log modification methods

Case 1: Last submission and no push

Execute the following command:

git commit --amend

git will open the $EDITOR editor, which will load the log of this submission so that we can edit it. After editing, save it to complete the modification.

Case 2: Last submission and pushed to the server

Execute the following command:

git commit --amend
git push origin master --force

Same as situation one. When using push to push to a remote server, you need to add --force to let the server update the history.

It should be noted that forcing the modified log to be pushed to the Git server may cause other people's local copies to be out of sync if they have modified them, so it is best to check with them.

Case 3: Old commits and not pushed

Assuming that the commit is the third to last commit, this can be viewed using git log.

$ git log
commit b1b451d218cc23b6c769f373164f2b89cf54d0aa
Author: clcaza <[email protected]>
Date: Sat Mar 10 19:09:08 2018 +0800

Add content

commit 04f0d1809d5d31cc6e930efcba47a5f3f7e93319
Author: clcaza <[email protected]>
Date: Sat Mar 10 19:08:24 2018 +0800

Add contentc

commit 94fc8feb916442d56b558d5c370f18f057298921
Author: clcaza <[email protected]>
Date: Sat Mar 10 19:07:08 2018 +0800

Add content

commit fd517efa9faf6a5ec71d0eac38fbcfa0cd689f40
Author: clcaza <[email protected]>
Date: Sat Mar 10 19:06:21 2018 +0800

init

Execute rebase

git rebase -i HEAD~3

It will open an editor that will show the last 3 commits, similar to this:

pick 94fc8fe add contenta
pick 04f0d18 add content c
pick b1b451d add content

You'll see that it's displayed in the order of the commits, which is the reverse order that git log shows. Locate the line where you want to edit the log, change pick to edit, and save.

Next is to modify the log content

git commit --amend

When you are done editing the log, remember to execute:

git rebase --continue

The purpose of rebase is to open up the history of commits and let you choose what to modify. Git will let you modify the content in a new branch. git rebase --continue allows you to return to the previous branch.

Case 4: Old submission and has been pushed to the server

The previous operation of editing the log is the same as in case 3:

git rebase -i HEAD~X
git commit --amend
git rebase --continue

X indicates the last submission.

After you finish editing the log, execute push:

git push origin master --force

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Window sets up a task plan to perform git updates (git pull) at regular intervals and hide the running cmd
  • git log queries the log according to specific conditions and counts the number of modified lines of code
  • The process of using Git in Idea
  • Solve the problem that Maven does not take effect after switching multiple branches in idea git
  • Git commit --amend Modify submission information operation

<<:  Datagrip2020 fails to download MySQL driver

>>:  Why is it not recommended to use an empty string as a className in Vue?

Recommend

How to change apt-get source in Ubuntu 18.04

When using apt-get to install, it will be very sl...

In-depth discussion on auto-increment primary keys in MySQL

Table of contents Features Preservation strategy ...

Spring Boot layered packaging Docker image practice and analysis (recommended)

Table of contents 1. Prepare the springboot proje...

The docker-maven-plugin plugin cannot pull the corresponding jar package

When using the docker-maven-plugin plug-in, Maven...

Deployment and configuration of Apache service under Linux

Table of contents 1 The role of Apache 2 Apache I...

Implementation of tomcat deployment project and integration with IDEA

Table of contents 3 ways to deploy projects with ...

Summary of several common methods of JavaScript arrays

Table of contents 1. Introduction 2. filter() 3. ...

Use CSS to create 3D photo wall effect

Use CSS to create a 3D photo wall. The specific c...

Use dockercompose to build springboot-mysql-nginx application

In the previous article, we used Docker to build ...

JavaScript style object and CurrentStyle object case study

1. Style object The style object represents a sin...

Several ways to set the expiration time of localStorage

Table of contents Problem Description 1. Basic so...

Detailed explanation on how to modify the default port of nginx

First find out where the configuration file is wh...

IDEA configuration process of Docker

IDEA is the most commonly used development tool f...