4.8 Exercise 8 - using the script
From the exercises repo, checkout branch exercise8/branchA and merge
exercise8/branchB. We should get a full-file conflict in primes.py.
Try to do this merge correcting history using the script from this recipe.
Let’s try to correct the history of the branch where the EOL format was
changed. Let’s use uix2dos as we did before to check it:
Listing 4.42:exercise 8 - EOL formats$ git show HEAD:primes.py | unix2dos -idum 0 21 0 $ git show MERGE_HEAD:primes.py | unix2dos -idum 27 0 0 $ git show $( git merge-base HEAD MERGE_HEAD ):primes.py | unix2dos -idum 0 21 0
And we can see how the format was changed in MERGE_HEAD,
a.k.a the other branch, so let’s checkout that branch and see where it
broke:
Listing 4.43:exercise 8 - Find out where it broke$ git checkout -f exercise8/branchB Switched to branch ’exercise8/branchB’ $ git log --stat --pretty=%h primes.py 491c86b primes.py | 3 +++ 1 file changed, 3 insertions(+) ea81ba7 primes.py | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) 55be073 primes.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
And we can see how the file was heavily modified on revision ea81ba7. Let’s
make really sure:
Listing 4.44:exercise 8 - double checking$ git show ea81ba7~:primes.py | unix2dos -idum 0 21 0 $ git show ea81ba7:primes.py | unix2dos -idum 24 0 0
And there we have it in all it’s glory. In ea81ba7s ancestor, it was all NIX breaks
and on ea81ba7 it was changed to DOS breaks.
Let’s use the recipe to correct the branch. First I will put the script in the
working tree, then I will try to run it:
Listing 4.45:exercise 8 - running recipe script$ ./correct_eol.sh ea81ba7~ exercise8/branchB primes.py correct_eol.sh copyright 2020 Edmundo Carmona Antoranz Released under the terms of GPLv2 file: primes.py EOL format: unix Checking out starting revision (55be073 Prime number calculation) Bringing over revision ea81ba7 (Check only already-known primes as divisors) Bringing over revision 491c86b (No need to check all divisors) Finished Check the results in the working tree and also the branch history with git log or gitk If you like the results, feel free to move the branch over here (for example, with ’git branch -f some-branch’)
Let’s check current branch history:
Listing 4.46:exercise 8 - running recipe script$ git log --graph --oneline HEAD exercise8/branchA exercise8/branchB * fa1aca4 (HEAD) No need to check all divisors * 434aec2 Check only already-known primes as divisors | * 2be7601 (exercise8/branchA) Let’s go up to 10000 |/ | * 491c86b (exercise8/branchB) No need to check all divisors | * ea81ba7 Check only already-known primes as divisors |/ * 55be073 Prime number calculation
And we can see how HEAD and exercise8/branchB have analogous
histories. Let’s compare the branches to make sure that they really are like each
other:
Listing 4.47:exercise 8 - comparing
results$ git diff -w HEAD exercise8/branchB $
Exactly what we wanted.Now we should move the branch and merge. I will skip
the moving step and will proceed to merge instead on HEAD:
Listing 4.48:exercise 8 - merging on HEAD$ git merge exercise8/branchA Auto-merging primes.py Merge made by the ’recursive’ strategy. primes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
And we can see how merge went fine this time around, because there were no
EOL discrepancies. Copyright 2020 Edmundo Carmona Antoranz