I am trying to merge changes from a file that is in git into one that is not under version control ( more context ) using a 3-way merge.
As is git merge-file <local> <base> <other>, which expects 3 files, and since I do not want to create intermediate files and forget to clean them, I used the bash replacement operator <(...), as I do quite often.
It turns out that this does not work as expected, as shown in the following example on git 2.4.2 and 2.4.3 on two different systems.
Example:
Let me create a little test for this so that we know what we are talking about. We will create a file foo.txt(one of git with two versions at least) and a file bar.txtthat is not under version control:
git init
echo -e 'foo\nbar' > foo.txt
git add foo.txt
git commit -m'init'
echo -e 'foo\nbar\nend' > foo.txt
git commit -a -m'end'
echo -e 'start\nfoo\nbar' > bar.txt
git show HEAD^:foo.txt > foo.txt.base
git show master:foo.txt > foo.txt.end
This leaves us with a couple of files that look like this:
foo.txt @HEAD ^ and foo.txt.base:
foo
bar
foo.txt @master and foo.txt.end:
foo
bar
end
bar.txt:
start
foo
bar
With intermediate files:
So now run git merge-file -p bar.txt foo.txt.base foo.txt.end:
start
foo
bar
end
This is the result that I would like to get with the following method.
With replacement process:
But if I run:, git merge-file -p bar.txt <(git show HEAD^:foo.txt) <(git show master:foo.txt)I get this output:
start
foo
bar
This is not expected and (sometimes!) echo $?Displays 1an error message.
What's even weirder, since I couldn't understand this behavior, I decided to re-run the above command (up arrow) and was even more puzzled when this output appeared:
<<<<<<< bar.txt
start
foo
bar
=======
foo
bar
end
>>>>>>> /dev/fd/62
, , , , :
<<<<<<< bar.txt
start
foo
bar
=======
>>>>>>> /dev/fd/62
, git merge-file -p bar.txt <(echo -e 'foo\nbar') <(echo -e 'foo\nbar\nend'), :
start
foo
bar
end
- ?
, , , , , , bash. , - .
, , , , : git show, git merge-file bash?