Git merge can wipe out changes, how to deal with it -


during merge commit creation. if change not staged , left outside merge commit.(this happen, , happens lot when doesn't quite known he's doing, blindly type mystery commands. or due misclick on gui git tool.[they non-technician, tried teach them, failed. let them use git can update files , keep date.]) change gone. merge commit won't have this change undoed msg. doesn't appear in merge commit. commit made change has info change. after merge change undoed without trace.

this horrifying, can't rely on merge commit info tell has been changed/undoed. in fact there's no easy way tell.

one approach solve limit ability merge onto master trustworthy maintainers.but fast developing mini group, add burden maintainer , slow down.

i'm wondering there enforce merge commit include info changes reverted not recorded?

or can ban merge operation completely, allow rebase make sure changes recorded explicitly?

no automated source tool can totally foolproof, fools clever. :-)

i think true people should rebase more merging (i.e., think git pull's default action, run git merge after running git fetch, wrong). no solution "people merges incorrectly" problem, because rebasing is merging! specifically, "rebase" commit, copy commit, if git cherry-pick. small , simple , not require fancy merge work, goes wrong , wind full blown merge. if people going merges wrong, may own rebases wrong too—and when rebase multiple commits, each commit gets copied, each 1 potential merge.

this means solution problem learn how merge. have leave sort of instruction others, note can see changes merge brought in, respect commit tip of branch before merging.

suppose have 2 branches, e.g., series of commits:

...--o--*--a-----b---c   <-- master          \           d--e--f--g--h   <-- feature/x 

when use git merge feature/x create new merge commit m on master, new commit two parents:

...--o--*--a-----b---c--m   <-- master          \             /           d--e--f--g--h   <-- feature/x 

this new commit has own independent source tree, commit.

in question, say:

this horrifying, can't rely on merge commit info tell has been changed/undoed. in fact there's no easy way tell.

but there is! commit m (whatever actual hash id is) has two parents. 1 of 2 parents "what on branch before", i.e., commit c. if want see has been changed in going commit c commit m, ask git show that:

git diff <hash-id-of-c> <hash-id-of-m> 

the output git diff same output any git diff: it's set of instructions show how take committed c, , modify make committed m.

you can, if want, have git produce set of instructions show how take committed h, , modify make committed m:

git diff <hash-id-of-h> <hash-id-of-m> 

as git diff, output set of instructions: "how take in first commit , change make in second commit."

there easy way see both of these

it's true git log -p, shows diff "parent commit" "child commit"—e.g., diff of a vs b, or b vs c—shows nothing when applied merge commit. however:

git show -m <hash-id-of-m> 

runs two git diff commands, 1 each parent, , shows both. think of -m "show merge" or "split merge (into 2 diffs)". -m flag is available in git log well:

git log -m -p 

shows each commit, 1 @ time, either simple diff (if it's not merge) or pair of simple diffs (if merge, 2 parents).

(there are, of course, ways one of these 2 well, answer long enough already.)


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -