When I merge code and there are conflicts, I have a quick command that lists all the files in the "modified" block of git status. It's a hack using grep and git status.
function gitfix() {
echo 'git status | grep modified:'
}
It's nice because I just do
emacs -nw $(gitfix)
and my editor loads up all the files that need conflicts resolved.
But I want a more proper version that uses git ls-files.
The git ls-files command has statuses like "modified" and "unmerged" and I'm not sure what those mean as regards merge conflicts.
Yeah, I know I'm lazy (I'm a programmer) for not figuring this out myself but intentionally creating conflicts is a pain in the ass if I'm the only committer. Anyone using git ls-files to list the files that have conflicts during a merge?
phd's comment referring to this line:
is a direct answer to what you want to do, but it's worth pointing out that
git statusdoes a lot more thangit ls-filescan do. Git is built around a "tool philosophy" and some tools are lower level and others are higher level;git statusis relatively high level and incorporates things that have to be done via multiple invocations of multiple lower-level tools:It will count how many commits the current branch is ahead and/or behind its upstream, if there is a current branch and it has an upstream. This requires using
git symbolic-refor similar to find the current branch,git rev-parseor similar to find its upstream, andgit rev-list --count --left-rightto do the counting.It will check to see if some files are unmerged, and if so, change its strategy. The
git ls-filescommand can do this but does not change strategy as a result: it takes one invocation ofgit ls-filesto discover this, and then one or more separate invocations later depending on the strategy.It will compare
HEAD(the current commit) vs the index:git ls-filescan do this, but it takes multiple invocations ofgit ls-files.It will compare the index vs the staging area:
git ls-filescan do this too, but again it takes multiple invocations.The main thing to know here is that
git ls-filesis oriented towards examining Git's index. The index itself is a complicated beastie, but its main contents are a list of <file name, staging number, hash ID, cache data> tuples:lstatdata and flags like assume-unchanged and skip-worktree: stuff intended to make Git go fast and/or be more useful.If all of these entries have staging number zero, there are no unmerged files. Any entry with a nonzero staging number represents an unmerged file, and the staging number tells us its source:
--ours, i.e., theHEADcommit;--theirs, i.e., the other commit.The name of the file in each of these up-to-three nonzero stage entries is normally the same for all three, but when a file was renamed, Git's index entries get a little squirrelly here. (There might, in theory, be more than three entries, though with just three stage numbers: Junio Hamano has mentioned on the mailing list that the intent was to allow multiple stage-1 entries during complex multiple-merge-base and/or octopus merges, for instance. In practice that doesn't happen, though. I think there are some additional issues here with the current index format that require either extensions or a new index format. But they're all extremely rare in practice anyway.) In any case, the presence of any nonzero stage numbers means that the index cannot be written out to a tree:
git write-treewill fail. Some Git scripts use this as a short-cut test for "do unmerged index entries exist":though technically
git write-treecould fail for other reasons (.git/indexbeing unwritable due to full file system, over-quota status, and/or permissions issues for instance).In any case, if all index entries are at stage zero, there are no unmerged files, and the index can be turned into a new commit. The file contents in this proposed commit may match those in the
HEADcommit, or not; they may match those in the working tree, or not; the index's set of files is independent of both of those.