tom@DESKTOP-5ABPUVE MINGW64 /e/testgit (master|BISECTING)
$ git log
commit fe6d1eca0825dba5594abe57d746478bca986203 (HEAD -> master)
Author: 徐x<xulang@inrecorp.com>
Date: Sun Feb 21 01:18:24 2021 +0800
conf
commit f8072add7f6de23c22125468be0aca79f3f77421
Author: 徐x<xulang@inrecorp.com>
Date: Sun Feb 21 01:17:36 2021 +0800
hello world
commit 2851f1dff33b4d919ab35daf79f30155f1a6e3da
Author: 徐x<xulang@inrecorp.com>
Date: Sun Feb 21 01:16:29 2021 +0800
hello
commit 4b99d1f26a6ed280888f6288d0ee51bdc43ebdaf
Author: 徐朗 <xulang@inrecorp.com>
Date: Sun Feb 21 01:15:52 2021 +0800
添加hell
commit 09719a2b3dd9a29012a27171ad23495775f9b23f
Author: 徐x<xulang@inrecorp.com>
Date: Sun Feb 21 00:49:03 2021 +0800
第二个
commit 130aede7986e345d6bc5ec8b65c73ea39eec3161
Author: 徐朗 <xulang@inrecorp.com>
Date: Sat Feb 20 23:25:22 2021 +0800
1. 第3次提交
将第3个合并到第3次提交
第3个
commit 28433dec3a93d58d0581a2b7853f37235e93ca9e
Author: 徐x<xulang@inrecorp.com>
Date: Sat Feb 20 23:24:48 2021 +0800
test 2
补交修改
commit 29daed9fcaddf125dde041456953a7f394e0dc31 (refs/bisect/skip-29daed9fcaddf125dde041456953a7f394e0dc31, refs/bisect/good-29daed9fcaddf125dde041456953a7f394e0dc31)
Author: 徐朗 <xulang@inrecorp.com>
Date: Sat Feb 20 23:23:55 2021 +0800
1.test 1
tom@DESKTOP-5ABPUVE MINGW64 /e/testgit (master|BISECTING)
$ git rebase -i 09719a2b3dd9a29012a27171ad23495775f9b23f
[detached HEAD 1cfceaa] 添加hell
Date: Sun Feb 21 01:15:52 2021 +0800
2 files changed, 1 insertion(+)
create mode 100644 c1.txt
create mode 100644 conf.txt
Successfully rebased and updated refs/heads/master.
tom@DESKTOP-5ABPUVE MINGW64 /e/testgit (master|BISECTING)
$ git commit --amend
[master 8a75242] hello world hhhh
Date: Sun Feb 21 01:17:36 2021 +0800
1 file changed, 1 insertion(+), 1 deletion(-)
tom@DESKTOP-5ABPUVE MINGW64 /e/code/iec103_-parser (master)
$ git log
commit 5a89e0fec32e97e9e45a62acc8f714952a46791f (HEAD -> master)
Author: xulang <1264445385@qq.com>
Date: Sun Feb 21 22:05:25 2021 +0800
add 3
commit 77824ec96931a960b7d6073f091dc7a1cf85d04e
Author: xulang <1264445385@qq.com>
Date: Sun Feb 21 22:04:45 2021 +0800
add 2
commit 8ed9909c5802c8a8958918353c6046b4a549ee65 (origin/master, origin/HEAD)
Author: xulang <1264445385@qq.com>
Date: Sun Feb 21 22:03:45 2021 +0800
add 1
add 3
commit 39fefec35a75678128fca680ed70b05d0123ed03
Author: xulang <1264445385@qq.com>
Date: Sun Feb 21 22:02:04 2021 +0800
add test.txt
commit 4f139bcbfb04154e9de01932acfef4bc1d7a725e (origin/develop)
Author: xulang <5202725+langneer@user.noreply.gitee.com>
Date: Sun Feb 21 20:10:35 2021 +0800
Initial commit
tom@DESKTOP-5ABPUVE MINGW64 /e/code/iec103_-parser (master)
$ git push
To gitee.com:langneer/iec103_-parser.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'gitee.com:langneer/iec103_-parser.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
tom@DESKTOP-5ABPUVE MINGW64 /e/code/iec103_-parser (master)
$ git push -f
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 487 bytes | 243.00 KiB/s, done.
Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-5.0]
To gitee.com:langneer/iec103_-parser.git
+ 8ed9909...4aab429 master -> master (forced update)
tom@DESKTOP-5ABPUVE MINGW64 /e/code/iec103_-parser (master)
$ git log
commit 4aab429efe7961e3cc56c9798f950b0767000f45 (HEAD -> master, origin/master, origin/HEAD)
Author: xulang <1264445385@qq.com>
Date: Sun Feb 21 22:04:45 2021 +0800
add 2
commit 0c60abcc37c145d6d42c16c39cbed74d42555c12
Author: xulang <1264445385@qq.com>
Date: Sun Feb 21 22:03:45 2021 +0800
add 1 & add3 together by rebase
add 3
commit 39fefec35a75678128fca680ed70b05d0123ed03
Author: xulang <1264445385@qq.com>
Date: Sun Feb 21 22:02:04 2021 +0800
add test.txt
commit 4f139bcbfb04154e9de01932acfef4bc1d7a725e (origin/develop)
Author: xulang <5202725+langneer@user.noreply.gitee.com>
Date: Sun Feb 21 20:10:35 2021 +0800
Initial commit
tom@DESKTOP-5ABPUVE MINGW64 /e/code/iec103_-parser (master)
总结
commit 4b99d1f26a6ed280888f6288d0ee51bdc43ebdaf 与commit fe6d1eca0825dba5594abe57d746478bca986203 合并
- 使用 git log 查看 提交记录
- 确认需要修改的那条记录的 head
- git rebase -i 【待修改的那条记录的前一条的head】
- 在弹出的文本编辑界面,调整你想要的的提交记录,可以上下移动head,待补交的提交 那条 pick 改为 squash
- git commit --amend
注意:
如果你要修改的commit已经push到了远程仓库,就比较危险;这时需要进行git push -f,将本地的覆盖远程;建议先将远程仓库clone 一个到一个新的文件夹备份