最近遇到了一个比较麻烦的OTP需求,由于是第一次做,所以做了很多的调查和试错,所以当需求完成的时候我的commit也高达12个之多

这对于一个票而言是不雅致的,所以我们要使用git来进行一些操作:

git rebase -i HEAD~n //n代表你要查看的提交记录条数

比如我要压缩4条commit:

git rebase -i HEAD~4

这个时候终端会出现:

pick d167a86 提交记录1
pick c56d2e4 提交记录2
pick c56d2e4 提交记录3
pick c56d2e4 提交记录4

# Rebase 7a28439..c56d2e4 onto 7a28439 (2 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# 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 out

可以看到我们提交的4条记录,假如,我需要将记录2、记录3、记录4合并到记录2(只能将最新的合并,即就是 记录1可以合并记录2,但是记录2不能合并记录1),我们将记录3、记录4中的pick改为squash然后保存更改退出后(Esc i 两个按键后可以修改内容,Esc Shift+: wq三个按键后为保存并退出,Esc Shift+: wq三个按键后为保存并退出,Esc Shift+: q三个按键后为退出),然后会进入:

# This is a combination of 3 commits.
# This is the 1st commit message:

提交记录2

# This is the commit message #2:

提交记录3

# This is the commit message #3:
提交记录4

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Fri Oct 12 14:58:12 2018 +0800
#
# interactive rebase in progress; onto 7a28439
# Last commands done (2 commands done):
#    pick d167a86 解决测试中提出的bug,修改etag缓存策略
#    squash c56d2e4 解决测试中的bug和修改UI布局,开发新漫画2.6.0版本
# No commands remaining.
# You are currently rebasing branch 'develope' on '7a28439'.
#
# Changes to be committed:
#       modified:   .gitignore
#       deleted:    .gradle/.DS_Store
#       deleted:    .gradle/2.14.1/.DS_Store
#       deleted:    .gradle/2.14.1/taskArtifacts/cache.properties
#       deleted:    .gradle/2.14.1/taskArtifacts/cache.properties.lock
#       deleted:    .gradle/2.14.1/taskArtifacts/fileHashes.bin
#       deleted:    .gradle/2.14.1/taskArtifacts/fileSnapshots.bin
#       deleted:    .gradle/2.14.1/taskArtifacts/fileSnapshotsToTreeSnapshotsIndex.bin
#       deleted:    .gradle/2.14.1/taskArtifacts/taskArtifacts.bin
#       deleted:    .gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin
#       deleted:    .gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock
#       deleted:    .gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin#       deleted:    .gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock

我们删除上面的"提交记录2、提交记录3、提交记录4"后,保存退出,就可以了

之后我们只要使用

git push --force origin master

提交到远端,在pr里就可以看到commit数量减少了。

最后修改:2023 年 06 月 06 日
收款不要了,给孩子补充点点赞数吧