Git: 如何删除出现在另一个分支上的重复提交?

Git: how to delete repeated commits that appear on another branch?

我的分支是这样的:

*   d3b91f2 (HEAD, origin/narrowdown_lblrtmprogram, narrowdown_lblrtmprogram, lowercase_main_src_code) resolve gi
t-pull conflict.  gitignore *.mod and *.so
|\  
| * 0ed828f number all the markers which a typical run goes past
| * 7a9fd6a gitignore *.o and lblrtm executables
| * 40e824a stop tracking lblrtm/lblrtm_v12.2_linux_intel_dbl
| * cfb6866 stop tracking some previously tracked files but are now in .gitignore
| * 314451c lay down markers in main program
| * a0d6edf gitignore *.mod
| * 5e9352a gitignore `runs/` directory
* | 2e48384 number all the markers which a typical run goes past
* | a0db0ed gitignore *.o and lblrtm executables
* | df52ddc stop tracking some previously tracked files but are now in .gitignore
* | 37fc6d1 lay down markers in main program
* | 9deee6a gitignore *.mod
* | 9ae357a (origin/trace_lblrtm_lw_flux_calc, trace_lblrtm_lw_flux_calc) gitignore runs/
* | 4ce55a0 gitignore *.o and lblrtm executables
* | 3691140 stop tracking lblrtm/lblrtm_v12.2_linux_intel_dbl
|/  
| * 3c8edd0 (origin/master, master) gitignore runs/
| * 969a8e1 gitignore *.o and lblrtm executables
|/  
* 11ed99d Revert "Add write() statements to mark path through lblrtm source code for example solar run"

似乎有两个分支在最高提交 d3b91f2 处合并。但是,从 36911402e48384 的提交实际上与从 5e9352a0ed828f 的提交相同。有没有办法摆脱那些从 5e9352a0ed828f 的冗余提交?因为在看

[jk@nuwaln01 aerlbl_v12.2_package]$ git log -10 narrowdown_lblrtmprogram --oneline
d3b91f2 resolve git-pull conflict.  gitignore *.mod and *.so
2e48384 number all the markers which a typical run goes past
a0db0ed gitignore *.o and lblrtm executables
df52ddc stop tracking some previously tracked files but are now in .gitignore
37fc6d1 lay down markers in main program
9deee6a gitignore *.mod
9ae357a gitignore runs/
4ce55a0 gitignore *.o and lblrtm executables
3691140 stop tracking lblrtm/lblrtm_v12.2_linux_intel_dbl
0ed828f number all the markers which a typical run goes past

[jk@nuwaln01 aerlbl_v12.2_package]$ git log -10 --oneline lowercase_main_src_code
d3b91f2 resolve git-pull conflict.  gitignore *.mod and *.so
2e48384 number all the markers which a typical run goes past
a0db0ed gitignore *.o and lblrtm executables
df52ddc stop tracking some previously tracked files but are now in .gitignore
37fc6d1 lay down markers in main program
9deee6a gitignore *.mod
9ae357a gitignore runs/
4ce55a0 gitignore *.o and lblrtm executables
3691140 stop tracking lblrtm/lblrtm_v12.2_linux_intel_dbl
0ed828f number all the markers which a typical run goes past

这些提交似乎不属于分支 narrowdown_lblrtmprogram 或分支 lowercase_main_src_code,所以我不能使用 git branch -d.

交互式变基可能会有所帮助。

git rebase -i 11ed99d

并用 d 标记标记要删除的提交。

只要确保有一个备份分支,否则如果出现故障,您将不得不执行 git reflog