Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what git log shows me didn't match what git rebase -i head~3 shows me

Tags:

git

github

rebase

I’m having problems with rebase. I want to squash some builds, but I can´t.

This is what I get when I execute the command git log –oneline:

git log --oneline
2e6d3cf Fix bug fetching data
4abe96e conflicts merged
34d130d latam_schedule with geotargeted languaje and data fetching
8687f73 removes extra lines, and add the includes I remove before.
eed4f10 unnecessary adds and sample block removed
d2d58e6 latam_schedule with geotargeted languaje and data fetching
75b1b6d parseo el string para extraer las horas.
8a3b067 Agrego un render con datos reales
d856ef1 Agrego un render de data dummy
7331f83 Alert removed(commented)
128bfc1 First LATAM commit
4dd79cb Merge pull request #1016 from matterhorn/disco-608-bugfix

The problem is that I don’t see the 2e6d3cf, 4abe96e and 34d130d commits that I want to squash when I execute git rebase HEAD~3.

Instead of the three commits I have, I see the following when I execute git rebase -i HEAD~3:

pick 34d130d latam_schedule with geotargeted languaje and data fetching
pick d2d58e6 latam_schedule with geotargeted languaje and data fetching
pick eed4f10 unnecessary adds and sample block removed
pick 8687f73 removes extra lines, and add the includes I remove before.
pick 2e6d3cf Fix bug fetching data

The thing is that I don’t know why d2d58e6, eed4f10 and 8687f73 are in the list. In the other hand, If I try to go ahead and squash, there are a lot of conflicts that shouldn’t be there (like trying to merge files that are too old).

This is what git log --oneline --graph --decorate shows

git log --oneline --graph --decorate
* 2e6d3cf (HEAD, matterhorn-latam/latam, latam) Fix bug fetching data
*   4abe96e conflicts merged
|\
| * 8687f73 (matterhorn-latam/master, master) removes extra lines, and add the includes I remove before.
| * eed4f10 unnecessary adds and sample block removed
| * d2d58e6 latam_schedule with geotargeted languaje and data fetching
* | 34d130d latam_schedule with geotargeted languaje and data fetching
|/
* 75b1b6d parseo el string para extraer las horas.
* 8a3b067 Agrego un render con datos reales
* d856ef1 Agrego un render de data dummy
* 7331f83 Alert removed(commented)
* 128bfc1 First LATAM commit

Any ideas?

like image 453
Werem Avatar asked Apr 10 '14 19:04

Werem


1 Answers

The necessary commits are not observed because HEAD~3 tells git to always follow the first parent in the commit tree, which happens to follow the merged branch history, which is, from your question, not the history you are after.

You need to explicitly select between commit^1 and commit^2 (and also commit^3 for octopus merges) to navigate the tree. For your example:

git log --oneline --graph --decorate
* 2e6d3cf HEAD
*   4abe96e HEAD^1 = HEAD~1 (! History branches here. !)
|\
| * 8687f73 HEAD^1^1 = HEAD^^ = HEAD~2
| * eed4f10 HEAD^^^ = HEAD~3
| * d2d58e6 HEAD^^^^ = HEAD~4
* | 34d130d HEAD^2   (! Note !)
|/
* 75b1b6d HEAD^2^ = HEAD^^^^^ = HEAD~5
* 8a3b067 ...
* d856ef1 ...
* 7331f83 ...

The order is a bit unusual here as a merge commit records the parents such that the HEAD at the time of the merge is always the first parent, and that implies that you must have been on the 8687f73 when you've done the merge for it to count as the first.

like image 197
mockinterface Avatar answered Oct 06 '22 01:10

mockinterface