On Tue, Oct 31, 2017 at 08:07:53PM -0700, Michael wrote:

> > How do I get git diff to show me the difference between two
> > different versions of one file?
> > 
> > I can say git diff tree-1 tree-2
> > 
> > I can say git diff file1
> > 
> > How do I ask for file1 in tree-1 versus file1 in tree-2?
> 
> Ok, perhaps a better question: Why isn't this doing what I expect?
> 
> keybounceMBP:extractor michael$ git status
> On branch new
> You have unmerged paths.
>   (fix conflicts and run "git commit")
>   (use "git merge --abort" to abort the merge)
> 
> Changes to be committed:
> 
>         modified:   ../../.github/ISSUE_TEMPLATE.md
>         modified:   ../../.travis.yml
>         modified:   ../../ChangeLog
> ...
> Unmerged paths:
>   (use "git add <file>..." to mark resolution)
> 
>         both modified:   adobepass.py
> 
> keybounceMBP:extractor michael$ git diff head^1 head^2 adobepass.py
> 
> If I understood the man page correctly, git diff tree-1 tree-2 path should 
> work.
> But that's not what I'm getting from that.

You understand the man page correcly but are you sure HEAD^1 and HEAD^2
is really what you want? To cite the manual page:

| A suffix ^ to a revision parameter means the first parent of that
| commit object.  ^<n> means the <n>th parent.

That is, the encantation you presented assumes the HEAD is a merge
commit and is asking Git to compare the states of "adobepass.py"
between the two parents of the merge commit at HEAD.

We seem to discuss a *failed attempt* to merge something, and whet this
happend, there's no merge commit yet. If that was your line of
reasoning, this could explain your attempt at using <rev>^<n>.
Was that the case?

If yes, Git has another approach to this task.
As I've said, when you're dealing with a failed merge attempt, there's
no merge commit yet; instead, the repo is in a special state, in which
it has a special ref called MERGE_HEAD which contains one or more (for
a so-called "octopus merge") "their" heads -- those which are being
merged.

When a merge conflict occurs, for each file with one or more conflicts,
Git does the following:
- Modifies the contents of that file in the work tree by placing there
  those conflict markers delimiting conflicting chunks.
- Modifies the index entry for that file -- by placing there references
  to the *three* versions of that file's contents: "base", "ours" and
  "theirs" -- with "base" being the version at the nearest preceding
  commits both branches had before they diverged.

So it's those index entries you'd want to inspect when dealing with a
merge conflict.

The syntax you want to use is explained in the gitrevisions(7) man page:

| :<n>:<path>, e.g. :0:README, :README
|   A colon, optionally followed by a stage number (0 to 3) and a colon,
|   followed by a path, names a blob object in the index at the given path.
|   A missing stage number (and the colon that follows it) names a stage 0
|   entry. During a merge, stage 1 is the common ancestor, stage 2 is the
|   target branch’s version (typically the current branch), and stage 3
|   is the version from the branch which is being merged.

So supposedly you'd need

  $ git diff :2:adobepass.py :3:adobepass.py

to ask the question «what are the differences in "adobepass.py" between
the HEAD of the branch I'm merging into and the branch I'm mering?»

Still, it may turn out that

  $ git diff HEAD MERGE_HEAD adobepass.py

would be a simpler approach.

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to