git merge 问题
远端分支更新后,本地需要使用 git pull 或者 git fetch 获取更新
有时候会出现拉取后,本地分支新出现一个 merge commit,这个 commit 会干扰到项目 commit 的历史线
所以我们一般在 git fetch 或者 git pull 后再使用 git reset --hard xxxx 来同步上下游的 commit 历史线(xxx 的上游最新的 commit 的 hash)
当然也可以手动禁止 git pull 后的自动合并
拓展:
git fetch
下载远程仓库的更新,但不会自动合并到当前分支,需要手动进行合并。git pull
下载远程仓库的更新,并且自动尝试将其合并到当前分支上。
一般情况下,绝对不要随便 rebase
如果远端分支更新了,远端分支上还有子模块也更新了,可以使用 --recurse-submodules
$ git pull official master --recurse-submodules From https://github.com/getsentry/sentry-native * branch master -> FETCH_HEAD Fetching submodule external/breakpad Fetching submodule external/crashpad Fetching submodule external/crashpad/third_party/lss/lss From https://chromium.googlesource.com/linux-syscall-support 9719c1e..ed31caa main -> origin/main * [new tag] v2022.10.12 -> v2022.10.12 Fetching submodule external/crashpad/third_party/mini_chromium/mini_chromium Fetching submodule external/crashpad/third_party/zlib/zlib From https://chromium.googlesource.com/chromium/src/third_party/zlib 63c0cec..24c07df main -> origin/main 63c0cec..24c07df master -> origin/master Fetching submodule external/libunwindstack-ndk Fetching submodule external/third_party/lss From https://chromium.googlesource.com/linux-syscall-support 063448f..ed31caa main -> origin/main Already up to date. Submodule path 'external/crashpad': checked out '6c9b05f368edb80ac113a54b49007c053eee1c97'
也不要随便 git merge 分支
$ git merge origin/feat/sentry_add_gzipped_with_compression Auto-merging CHANGELOG.md CONFLICT (content): Merge conflict in CHANGELOG.md Automatic merge failed; fix conflicts and then commit the result.
这样操作后,会扰乱原来的 commits,就像这样
$ git log --oneline 696d918f (HEAD -> feat/sentry_add_gzipped_with_compression, origin/feat/sentry_add_gzipped_with_compression) Merge remote-tracking branch 'origin/feat/sentry_add_gzipped_with_compression' i nto feat/sentry_add_gzipped_with_compression d14457da Update crashpad build script b9e7882b Remove build remnants of CMake <= 3.12... cac38477 Fix format in sentry_transport.c 726a876f Update change-log 66b532d6 Revert "separate crashpad gzip choice" 260760e8 separate crashpad gzip choice e060cc8d format 2184c014 add change log 4fc501c2 restore ENVELOPE_MIME define f69f0b83 rename vars and improve code logic 3f2c13c1 lint 09643e79 improve format cc0411e1 add # 66f01542 add GZIP_COMPRSSION defintion 780770eb modify some code 29761d1f reuse body/_owned 43e44759 use sentry__xx 75654b3e add zlib.h 92ece2b1 add gzip compression fda2a372 (official/master, master) Add user feedback capability to the Native SDK (#966) 33c1198d Update crashpad build script 4dcbbae6 Remove build remnants of CMake <= 3.12... 6b879c00 Fix format in sentry_transport.c 8094b4ad Update change-log c98f2193 Revert "separate crashpad gzip choice" 282100fc separate crashpad gzip choice 9bec2cba format e830aea2 add change log 9b1bc43f build(deps): bump black from 24.2.0 to 24.3.0 in /tests (#967) 48fc18e9 restore ENVELOPE_MIME define 56ed2f6d rename vars and improve code logic 2530bdd6 lint 32e90a4b improve format db233905 add #
红色部分全部重复了,遇到这种情况,先保持冷静
使用 git reset --hard 定位到最新的 commit,具体可以观察 PR 上最后一个 commit 提交记录
$ git reset --hard 33c1198d HEAD is now at 33c1198d Update crashpad build script
现在就正常了
$ git log --oneline 33c1198d (HEAD -> feat/sentry_add_gzipped_with_compression) Update crashpad build script 4dcbbae6 Remove build remnants of CMake <= 3.12... 6b879c00 Fix format in sentry_transport.c 8094b4ad Update change-log c98f2193 Revert "separate crashpad gzip choice" 282100fc separate crashpad gzip choice 9bec2cba format e830aea2 add change log 48fc18e9 restore ENVELOPE_MIME define 56ed2f6d rename vars and improve code logic 2530bdd6 lint 32e90a4b improve format db233905 add # c07a6a4e add GZIP_COMPRSSION defintion 2fac701c modify some code 0f370b02 reuse body/_owned 0d36bb08 use sentry__xx cd7f0825 add zlib.h f60449b6 add gzip compression e812e7c7 fix: failing clang-asan/llvm-cov tests (#965) 8f262299 ci: build zlib for mingw (#964) 2ae5de65 (origin/master) chore: add note about experimental state of standalone SDK (#952) 0043edf8 docs: provide example for breadcrumb data property (#951) 5596cbba build: remove obsolete CRASHPAD_WER_ENABLED (#950) 9ea60904 (upstream/master) Merge branch 'release/0.7.0' 4ec95c07 (tag: 0.7.0) release: 0.7.0
此时再 git merge master,以解决冲突
$ git merge master Auto-merging CHANGELOG.md CONFLICT (content): Merge conflict in CHANGELOG.md Automatic merge failed; fix conflicts and then commit the result.
再次查看 commits
$ git log --oneline 42ebfb57 (HEAD -> feat/sentry_add_gzipped_with_compression) Merge branch 'master' into feat/sentry_add_gzipped_with_compression fda2a372 (official/master, master) Add user feedback capability to the Native SDK (#966) 33c1198d Update crashpad build script 4dcbbae6 Remove build remnants of CMake <= 3.12... 6b879c00 Fix format in sentry_transport.c 8094b4ad Update change-log c98f2193 Revert "separate crashpad gzip choice" 282100fc separate crashpad gzip choice 9bec2cba format e830aea2 add change log 9b1bc43f build(deps): bump black from 24.2.0 to 24.3.0 in /tests (#967) 48fc18e9 restore ENVELOPE_MIME define 56ed2f6d rename vars and improve code logic 2530bdd6 lint 32e90a4b improve format db233905 add # c07a6a4e add GZIP_COMPRSSION defintion 2fac701c modify some code 0f370b02 reuse body/_owned 0d36bb08 use sentry__xx cd7f0825 add zlib.h f60449b6 add gzip compression e812e7c7 fix: failing clang-asan/llvm-cov tests (#965) 8f262299 ci: build zlib for mingw (#964) 2ae5de65 (origin/master) chore: add note about experimental state of standalone SDK (#952) 0043edf8 docs: provide example for breadcrumb data property (#951)
没啥问题就 git push -f 吧,git push 会一直提示 Updates were rejected because the tip of your current branch is behind
不管它了,先解决重复 commits 问题吧
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
2021-03-05 win32 - 创建无GUI的消息循环(包含线程窗口的说明)