Joined September 2014
·

Alex Pulver

Israel
·

Thanks a lot for the post - very interesting! One comment though - it seems that -p does preserve merge history, but it modifies the recreated commit from which the merge was performed. Below is an example (a bit long) flow that illustrates this issue (output of most commands was removed, only the relevant output was included) - the preserved commit contains the merge result, and not the initial commit as on the feature branch:


git init --bare /tmp/rebase
git clone /tmp/rebase /tmp/rebaseclone1
git clone /tmp/rebase /tmp/rebase
clone2

cd /tmp/rebase_clone1
touch file.txt
git add .
git commit -m 'added file.txt'
git push origin master

cd /tmp/rebase_clone2
git pull
git checkout -b feature
echo 2 file.txt
git commit -a -m 'wrote 2'
git checkout master
git merge --no-ff feature

git logk # logk is an alias for nicely formatted log command.
* f55163e - (HEAD, master) Merge branch 'feature' (43 seconds ago) <Alex Pulver>
|\
| * 2b51d05 - (feature) wrote 2 (43 seconds ago) <Alex Pulver>
|/
* 34edfbc - (origin/master) added file.txt (43 seconds ago) <Alex Pulver>

cd /tmp/rebase_clone1
echo 1 file.txt
git commit -a -m 'wrote 1'
git push origin master

cd /tmp/rebase_clone2
git push origin master
To /tmp/rebase
! [rejected] master -master (fetch first)
error: failed to push some refs to '/tmp/rebase'
...

git fetch
git logk --all
* 7abff92 - (origin/master) wrote 1 (2 minutes ago) <Alex Pulver>
| * f55163e - (HEAD, master) Merge branch 'feature' (5 minutes ago) <Alex Pulver>
| |\
|/ /
| * 2b51d05 - (feature) wrote 2 (5 minutes ago) <Alex Pulver>
|/
* 34edfbc - added file.txt (5 minutes ago) <Alex Pulver>

git rebase -p origin/master
error: could not apply 2b51d05... wrote 2
...
pico file.txt # resolve the conflicts.
git add file.txt
git rebase --continue

git logk --all
* a7e3457 - (HEAD, master) Merge branch 'feature' (86 seconds ago) <Alex Pulver>
|\
| * 4528467 - wrote 2 (2 minutes ago) <Alex Pulver>
|/
* 7abff92 - (origin/master) wrote 1 (5 minutes ago) <Alex Pulver>
| * 2b51d05 - (feature) wrote 2 (8 minutes ago) <Alex Pulver>
|/
* 34edfbc - added file.txt (8 minutes ago) <Alex Pulver>

git checkout 4528467
cat file.txt
1
2

git checkout 2b51d05
cat file.txt
2
</pre>

Achievements
1 Karma
0 Total ProTip Views