0

I have the following git alias

[alias]  
remaster = !"git checkout $1 & git diff-tree -r --patch --diff-filter=DM $1..master"

When using the above command by hand I get the following stdout:

$ git diff-tree -r --patch development..master --diff-filter=DM

diff --git a/subfolder/subfile.exe b/subfolder/subfile.exe
deleted file mode 100644
index e69de29..0000000
diff --git a/virus.exe b/virus.exe
deleted file mode 100644
index e69de29..0000000

When using the alias the output is not available therefore I cannot use it to patch:

$ git remaster development
xetra11
  • 7,671
  • 14
  • 84
  • 159

1 Answers1

1

Git aliases are mainly designed to call one other git command, not more than one arbitrary commands. That is, you usually do something like

[alias]
    aa = commit --amend -a --no-edit

Note that the above only says commit, not git commit. Anyway, there's a common trick to still achieve what you want, by using a dummy shell function:

[alias]
    remaster = "!f() { git checkout $1 && git diff-tree -r --patch --diff-filter=DM $1..master | git apply; }; f"

(I've also changed the single & to correctly say &&.)

sschuberth
  • 28,386
  • 6
  • 101
  • 146