Commit to comb

1. Modify the submission information

1. Modify the latest submission information

To modify the latest commit information, run git commit –amend as follows:

Step 1. View the current submission record

commit 5dda4591f28955e4eaba649e46301e0d20869ffa (HEAD -> master, tag: test)
Author: xxx <[email protected]>
Date:   Sun Dec 13 19:02:57 2020 +0800

    add demo.html and modify readme

commit 84ed89a79f290cbdab68bdc9468859a05d9fac77
Author: xxx <[email protected]>
Date:   Sun Dec 13 18:57:21 2020 +0800

    init proj
Copy the code

Step 2. Run the command to enter the interactive mode and edit the latest submission information. Save the modification and exit

git commit --amend
Copy the code

Step 3. Check the Git log again

commit d580b0531381c4e2384296374515183365bfcefb (HEAD -> master)
Author: xxx <[email protected]>
Date:   Sun Dec 13 19:02:57 2020 +0800

    add demo.html and modify readme has been change

commit 84ed89a79f290cbdab68bdc9468859a05d9fac77
Author: xxx <[email protected]>
Date:   Sun Dec 13 18:57:21 2020 +0800

    init proj
Copy the code

Note that the hash of the commit has changed, indicating that a new COMMIT has been created

2. Modify the previous submission information

Git rebase git rebase git rebase

Commit (d580B0531381) commit (d580B0531381)

commit 988031473715ddbb3ba675aaaec8ee708b45cfb0 (HEAD -> master)
Author: your name <[email protected]>
Date:   Wed Dec 16 00:19:02 2020 +0800

    modify demo.html

commit d580b0531381c4e2384296374515183365bfcefb
Author: your name <[email protected]>
Date:   Sun Dec 13 19:02:57 2020 +0800

    add demo.html and modify readme has been change

commit 84ed89a79f290cbdab68bdc9468859a05d9fac77
Author: your name <[email protected]>
Date:   Sun Dec 13 18:57:21 2020 +0800

    init proj
Copy the code

Step 2. Use git rebase to benchmark the last commit you want to change (commit: 84ed89a79f290).

Git rebase - I 84ed89a79f290 Pick d580b05 add demo. HTML and modify readme has been change pick 9880314 modify demo. HTML # Rebase 84ed89a.. 9880314 onto 84ed89a (2 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit's log message # x, exec <command> = run command (the rest of the line) using shell # b, break = stop here (continue rebase later with 'git rebase --continue') # d, drop <commit> = remove commit # l, label <label> = label current HEAD with a name # t, reset <label> = reset HEAD to a label # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>] # . create a merge commit using the original merge commit's # . message (or the oneline, if no original merge commit was # . specified). Use -c <commit> to reword the commit message. # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented outCopy the code

Pick is simply to pick out the commit and append it to the base specified by Rebase. According to the description, we should use the reword command.

reword d580b05 add demo.html and modify readme has been change pick 9880314 modify demo.html ... Git will tell you that you have successfully modified your commitCopy the code

Step 4. View the Git log

commit 031d6955860af34ae5b0af4d333012665a54a0c0 (HEAD -> master)
Author: your name <[email protected]>
Date:   Wed Dec 16 00:19:02 2020 +0800

    modify demo.html

commit a527ec35ded4028b924d02e25cf954f2f9ef6fa0
Author: your name <[email protected]>
Date:   Sun Dec 13 19:02:57 2020 +0800

    add demo.html and modify readme has been changed again!

commit 84ed89a79f290cbdab68bdc9468859a05d9fac77
Author: your name <[email protected]>
Date:   Sun Dec 13 18:57:21 2020 +0800

    init proj
Copy the code

(“has been changed “-> “has been changed again!”) ), and the HASH ID of the commit has been changed to try to append the original commit to the benchmark instead of regenerating the commit object

Integration of submission

Multiple consecutive commits are consolidated into one commit

During development, you may encounter the need to integrate multiple commits as follows

Step 1. First observe the current submission record

commit 2696a6b43c3252ed26f1eecd06d0fb443de6ca81 (HEAD -> master)
Author: your name <[email protected]>
Date:   Sun Dec 20 00:44:59 2020 +0800

    test commit

commit 031d6955860af34ae5b0af4d333012665a54a0c0
Author: your name <[email protected]>
Date:   Wed Dec 16 00:19:02 2020 +0800

    modify demo.html

commit a527ec35ded4028b924d02e25cf954f2f9ef6fa0
Author:  your name <[email protected]>
Date:   Sun Dec 13 19:02:57 2020 +0800

    add demo.html and modify readme has been changed again!

commit 84ed89a79f290cbdab68bdc9468859a05d9fac77
Author:  your name <[email protected]>
Date:   Sun Dec 13 18:57:21 2020 +0800

    init proj
Copy the code

Step 2. The rebase command is used to merge the two commits. The first commit is used as the baseline

> git rebase -i 84ed89a79f290 Pick a527ec3 add demo. HTML and modify readme has been changed again! squash 031d695 modify demo.html pick 2696a6b test commit ...Copy the code

The squash parameters are described as follows, which meets our requirements this time

s, squash <commit> = use commit, but meld into previous commit

Step 3. Save the Settings and exit the previous Step. The system automatically switches to the description writing Step and specifies the description for the new COMMIT

# This is a combination of 2 commits.
commbo commit

# This is the 1st commit message:

add demo.html and modify readme has been changed again!

# This is the commit message #2:

modify demo.html
Copy the code

Step 4. Check the new Git log and find that it has been merged successfully

commit 83bc3c142f7dfda3dd2cae387b69bd7c7162d9b0 (HEAD -> master)
Author: your name <[email protected]>
Date:   Sun Dec 20 00:44:59 2020 +0800

    test commit

commit 20bbb14ede2297040f0d08fdde9712d80aea6984
Author: your name <[email protected]>
Date:   Sun Dec 13 19:02:57 2020 +0800

    commbo commit

    add demo.html and modify readme has been changed again!

    modify demo.html

commit 84ed89a79f290cbdab68bdc9468859a05d9fac77
Author: your name <[email protected]>
Date:   Sun Dec 13 18:57:21 2020 +0800

    init proj
Copy the code

Multiple non-consecutive commits are consolidated into one commit

The specific operation method is similar to the preceding steps. The difference is that you need to adjust the sequence of several non-consecutive commits together. For example, if you want to integrate commit 3 and commit 5, put commit 5 after commit 3 in rebase and use squash parameter.

Note that adjusting the COMMIT order is likely to cause conflicts that need to be resolved