Git合并冲突总是采取最新的文件 [英] Git merge conflict to always take the newest file
问题描述
我怎样才能让一个Git冲突总是通过采用最新的文件(最新更改的时间戳),completley没有及时解决?
我建立了syncscript git后端,并且我从不想实际合并文件,只需覆盖所有旧版本,并使用最后编辑/删除/添加的那个。
$ b 编辑:使用最新的文件,我的意思是包含该文件的最新提交。
为了我的目的,它被硬编码到主分支和原点远程。
#!/ usr / bin / env sh
if git merge-file -p -q$ 2$ 1$ 3>的/ dev / null的;
然后git merge-file$ 2$ 1$ 3;
else
MINE = $(git log --format =%ct--no-merges master -1);
THEIRS = $(git log --format =%ct--no-merges origin / master -1);
if [$ MINE -gt $ THEIRS];
然后git merge-file -q --ours$ 2$ 1$ 3;
else git merge-file -q - 他们的$ 2$ 1$ 3;
fi
fi
总之,我使用git-日志不是合并,格式化为UNIX时间戳,然后比较它们并运行我们的eiter或它们的版本的自定义git-merge。
作为一个小红利,它首先进行检查,看看是否可以合并文件而不发生冲突。如果可能的话,它会合并这两个文件。
How can I make a git conflict ALWAYS get resolved by taking the newest file (latest changed timestamp), completley without a prompt?
I am building a syncscript with git backend, and I never want to actually merge a file, just override all older copies with the one that was edited/deleted/added last.
Edit: With newest file, I mean newest commit containing that file.
I came up this little merge driver that does what I want. For my purpose it is hard coded to the "master" branch and to the "origin" remote. I do not know how to make these parts dynamic.
#!/usr/bin/env sh
if git merge-file -p -q "$2" "$1" "$3" > /dev/null;
then git merge-file "$2" "$1" "$3";
else
MINE=$(git log --format="%ct" --no-merges master -1);
THEIRS=$(git log --format="%ct" --no-merges origin/master -1);
if [ $MINE -gt $THEIRS ];
then git merge-file -q --ours "$2" "$1" "$3";
else git merge-file -q --theirs "$2" "$1" "$3";
fi
fi
In short I look for the last commit with git-log that was not a merge, formatted as UNIX timestamp, then I compare them and run a custom git-merge with eiter ours or their version.
As a little bonus, it first makes a check to see if it is possible to merge the file without conflict. If that is possible, it merges both files.
这篇关于Git合并冲突总是采取最新的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!