1

Let's say I have attempted a merge from branch A to branch B -- the merge failed because there are conflicts in file F.

Until now I have been doing a

git diff --word-diff HEAD:F master:F 

which gets boring after a while. Is there some alternative out of the box command that allows me to avoid this, or will I have to save this little script and make it accessible somewhere in my computer's $PATH?

1
  • Did you try a git alias ? Commented Jul 19, 2016 at 15:26

2 Answers 2

3

Whenever the scope of a repeated operation is going to be limited (i.e. a relatively short session inside a single terminal) and not likely to occur again in the near future, I prefer to wrap it in a bash function in the current shell. This avoids the problem of having to find a good name for the script before putting it in $PATH.

In your case, typing the following line into the shell

function mydiff() { git diff --word-diff HEAD:"$1" master:"$1"; } 

will enable you performing diff with a much shorter command mydiff F.

Sign up to request clarification or add additional context in comments.

Comments

1

As Leon answered you can make a tiny shell function (or shell alias) for this, or as Frodon commented you can make a Git alias.

More usefully, during a conflicted merge, the local (--ours) and other (--theirs) commit IDs are conveniently named HEAD and MERGE_HEAD respectively. Hence you don't have to hard-code the name master into your shell function, shell alias, or Git alias, and:

[alias] wdiff = "!f() { git diff --word-diff HEAD:\"$1\" MERGE_HEAD:\"$1\"; }; f" 

would do the trick here, for instance.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.