qAp
qAp

Reputation: 1189

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

I have a situation where my branches look like this:

*   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"

There appears to be two branches that are merged at the topmost commit d3b91f2. However, commits from 3691140 to 2e48384 are effectively the same as those from 5e9352a to 0ed828f. Is there a way to get rid of those redundant commits from 5e9352a to 0ed828f? Because looking at

[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

and

[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

these commits do not seem to belong to either branch narrowdown_lblrtmprogram or branch lowercase_main_src_code, so I cannot use git branch -d.

Upvotes: 0

Views: 41

Answers (1)

Jakub Kopřiva
Jakub Kopřiva

Reputation: 511

interactive rebase might be helpful.

git rebase -i 11ed99d

and flag commits you want to delete with d marker.

Just make sure to have a backup branch or you will have to do a git reflog if something fails.

Upvotes: 1

Related Questions