0

On Windows, I'm trying to create an alias for Git Add to automatically select only C# related files.

My current alias is:

acs = add *.cs *.csproj *.sln

I keep getting this error: fatal: pathspec '*.sln' did not match any files, which is expected, since the specific folder I am in contains only the project and not the solution. (i.e. *.cs and *.csproj both exist)

I want to create an alias that would work for all C# folders.


Say I have 2 folders.

Folder1 contains:

  • 1.foo
  • 2.foo

Folder2 contains:

  • 1.foo
  • 2.bar

In Git Add, is it possible to create a line that would work for both folders, regardless of the presence of the files mentionned in the wildcards ?

I would have expected (hoped for) something like:

git add *.foo|*.bar

Is there any OR wildcard ?

2 Answers2

1

try this:

acs = add --ignore-errors *.cs *.csproj *.sln
Woodrow Douglass
  • 2,605
  • 3
  • 25
  • 41
  • No, exact same result, unfortunately. This is a fatal error, while --ignore-errors only works for indexing problem (if I understand correctly) – Balthazar40 Oct 31 '13 at 15:33
1

I don't see any way to make git add's convenience globbing ignore a pattern that doesn't match anything, but there are much more powerful ways to build command lines.

First, a handy alias:

git config --global alias.files 'ls-files -oc --exclude-standard'

then

git config alias.acs '!git files -z *.cs *.csproj *.sln | xargs --null git add --'

gets you what you want.

jthill
  • 55,082
  • 5
  • 77
  • 137
  • I needed to add --global and double quotes in order for the 2nd alias to be created, but it ended up working like a charm ! Thanks ! – Balthazar40 Oct 31 '13 at 18:16
  • Actually, what I really used was `git config --global alias.acs "!git files -z \*.cs \*.csproj \*.sln | xargs --null git add --"`. – Balthazar40 Oct 31 '13 at 18:31
  • I yanked the backslashes but left the suffix selection per-repo for some reason I can't quite explain even to myself... – jthill Nov 01 '13 at 19:38