Participate in the 21st day of The November Gwen Challenge, see the details of the event: 2021 last Gwen Challenge

Here’s the thing. I wrote a note and submitted it frequently every day. A look today, good guy unexpectedly so many submitted records, so I want to simplify. For example, “finish 4.1”, “finish 4.2”, etc., are merged into “finish Chapter 4”.

Now combine these two:

Now modify it.

1. View the submission information

Use git log to view all commit information for the current repository.

2. Modify the submission information

  • git rebase -i HEAD~n

    Displays the n recent commits in chronological order from nearest to far. Such asgit rebase -i HEAD~3 Enter viM mode and enter in English state:qCan exit.

Because the information I’m merging is the first two pieces of information. The last three pieces of information are definitely invisible.

  • git rebase -i --rootThis lists all commit information from far to near.

Next we modify :smile:.

Take a look at the message:

Commands:

  • p, pick = use commit
  • e, edit = use commit, but stop for amending
  • s, squash = use commit, but meld into previous commit
  • f, fixup [-C | -c] = like “squash” but keep only the previous commit’s log message, unless -C is used, in which case keep only this commit’s message; -c is same as -C but opens the editor
  • Pick is the default commit, leave it alone
  • Edit is a modification of this
  • S is for merge
  • F is also merged, but only the first commit information is retained. If -c is added, only the latest commit information is kept

So you can merge with either -s or -f

squash

The waysquashThe principle is to merge a commit modified to S into its previous commit. Such as:Now let’s try it. Press in English input stateiGo into edit mode and change pick to S. After the modificationEscExit editing mode. then:, the inputwqSave the changes and exit the file.

And then you’ll go to the commit file after the merge, and it’ll show you what happened after the merge, the first commit, the second commit.Of course, you can also modify the content. I’m only keeping the first commit for now. Even after the modificationEscExit editing mode. The input:wq.After the modification git push origin master -f.

Now let’s see, the merger is successful.

fixup

The principle of fixup is to merge several commits, but retain only one information at the end.

If you are usingfAll information is merged into the previous commit, and the farthest one is saved.

As shown in the figure, change the prefix of 4.3, 4.6 and 5 to F, then the three will be merged into 3 eventually.

There are only 3 commits left after the merge. If you havefInstead off -cIs merged to the previous commit, but the most recent commit information is saved.

Git push Origin master -f