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?

Blog    

Recommend

Analysis of the differences between Iframe and FRAME

1. Use of Iframe tag <br />When it comes to ...

Detailed explanation of computed properties in Vue

Table of contents Interpolation Expressions metho...

MySQL and MySQL Workbench Installation Tutorial under Ubuntu

Ubuntu install jdk: [link] Install Eclipse on Ubu...

Docker Basics

Preface: Docker is an open source application con...

How to remotely log in to the MySql database?

Introduction: Sometimes, in order to develop a pr...

CSS3 flip card number sample code

I received a task from the company today, and the...

MySQL automatically inserts millions of simulated data operation code

I use Navicat as my database tool. Others are sim...

WeChat applet learning wxs usage tutorial

What is wxs? wxs (WeiXin Script) is a scripting l...

How to modify the port mapping of a running Docker container

Preface When docker run creates and runs a contai...

Solution to the MySQL error "Every derived table must have its own alias"

MySQL reports an error when executing multi-table...

Using streaming queries in MySQL to avoid data OOM

Table of contents 1. Introduction 2. JDBC impleme...