1

I'm trying to add (edit: THE DELETE operation) of these files with the text "generated" in it, and it doesn't work. I'm using PowerShell.

#       deleted:    Apica.WebPerformance.Web.Controllers/SharedController.generated.cs
#       deleted:    Apica.WebPerformance.Web.Controllers/SidebarController.generated.cs
#       deleted:    Apica.WebPerformance.Web.Controllers/SubscriptionController.generated.cs
#       deleted:    Apica.WebPerformance.Web.Controllers/ToolsController.generated.cs
#       deleted:    Apica.WebPerformance.Web.Controllers/UnauthorizedController.generated.cs
#       deleted:    Apica.WebPerformance.Web.Controllers/UrlCheckController.generated.cs
#       deleted:    Apica.WebPerformance.Web.Controllers/UrlCheckWizardController.generated.cs
#       deleted:    Apica.WebPerformance.Web.Controllers/UserSessionContextController.generated.cs
#       deleted:    Apica.WebPerformance.Web.Controllers/UserSessionContextDataController.generated.cs
#       modified:   Apica.WebPerformance.Web.Controllers/ViewModels/Checks/CheckListViewModel.cs
#       modified:   Apica.WebPerformance.Web.Controllers/ViewModels/Checks/ChecksOverviewViewModel.cs
#       deleted:    Apica.WebPerformance.Web.Controllers/WebSocketCheckWizardController.generated.cs
#       deleted:    Apica.WebPerformance.Web.Controllers/WebSocketJmsCheckWizardController.generated.cs
#       deleted:    Apica.WebPerformance.Web.Controllers/WidgetsController.generated.cs
#       deleted:    Apica.WebPerformance.Web.Controllers/WizardController.generated.cs
#       modified:   Apica.WebPerformance.Web/Assets/Common/Css/jquery.multiSelect.css
#       modified:   Apica.WebPerformance.Web/Views/Examples/MultiSelect.cshtml
#
C:\git_apica\WebPerformance.Web [ViewModelRefactor +6 ~2 -0 | +0 ~6 -52]> git add *generated.cs
C:\git_apica\WebPerformance.Web [ViewModelRefactor +6 ~2 -0 | +0 ~6 -52]> git add '*generated.cs'
C:\git_apica\WebPerformance.Web [ViewModelRefactor +6 ~2 -0 | +0 ~6 -52]> git add '*generated*'
C:\git_apica\WebPerformance.Web [ViewModelRefactor +6 ~2 -0 | +0 ~6 -52]> git add \*generated.cs
C:\git_apica\WebPerformance.Web [ViewModelRefactor +6 ~2 -0 | +0 ~6 -52]> git add '*generated.cs'
C:\git_apica\WebPerformance.Web [ViewModelRefactor +6 ~2 -0 | +0 ~6 -52]> 

None of these commands actually stage anything. It works file by file, however.

Roman
  • 19,581
  • 6
  • 68
  • 84
imbageek
  • 609
  • 5
  • 18
  • That should work. Can you try it with a new test repository you can upload somewhere? – Daniel Hilgarth Feb 12 '13 at 14:29
  • Yes, i'm using PoshGit. I also think this really should work and can't understand why it doesn't. Oh i forgot to say that these files are actually deleted, and that i want to commit the deletion of those. (It's red colored) – imbageek Feb 13 '13 at 08:34
  • See my answer, no command that relies on the shell to find deleted files will work because the files don't exist on the file system any more. – asm Feb 13 '13 at 13:50
  • @AndrewMyers `-u` matches files in the index rather than working tree, so giving a pattern will work even if files are not on the file system. – Roman Feb 13 '13 at 16:41
  • @R0MANARMY The git documentation is written in such a way to make it sounds as though git is processing the file globs. This is not how unix shells work though. git never even sees the unexpanded file glob, the shell expands it. git then processes the list of files that result. It's straightforward to verify this. Just delete a file in the current directory then run `git add -u *`. The deleted file will _not_ be added. I don't have access to Powershell, and it does rely on git to process the glob, but I would be astonished if git implemented semantics other than that of a unix shell. – asm Feb 13 '13 at 20:40
  • @AndrewMyers I tried it with deleting some files and adding them using a pattern, it seems to have worked (using msysgit on Windows, so might act a little differently from unix shells). – Roman Feb 13 '13 at 21:58

3 Answers3

2

Perhaps this, good sir

find | grep generated.cs | xargs git add
Zombo
  • 1
  • 62
  • 391
  • 407
  • Didn't work due to missing argument, however it seems overkill in order to do something so simple. Thanks for the contribution though! – imbageek Feb 13 '13 at 08:37
2

Looks like there are two minor issues with your command

  1. It looks like the files you want to stage are a directory down from where the shell is, so you need to add a leading *.
  2. You want to stage files that have been removed. There are two ways to do that calling git rm <file name> in each removed file or using the -u flag of the add command. From documentation (emphasis mine):

    -u
    --update
    Only match against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed.

git add -u *\*.generated.cs should work.

Roman
  • 19,581
  • 6
  • 68
  • 84
  • didnt work, same result. And your observation is correct. However you wrote this you didn't know by my question that i'm actually trying to stage removal of these files. But at any rate it is the git add command that stages these removals. – imbageek Feb 13 '13 at 08:40
  • @imbageek Updated answer, tested it locally and seems to do the right thing, let me know if it works. – Roman Feb 13 '13 at 18:58
  • 1
    `git add -u *\*.generated.cs` and `git rm *\*.generated.cs` both work for me in PowerShell with git 1.8.0.msysgit.0. – dahlbyk Mar 12 '13 at 02:42
0

The problem here is that wildcards will only expand to file names that are on the file system (since the shell is doing the expansion, not git). Since you've deleted the files they aren't on the file system so you need a different command. There are two simple ways to add the delete operation.

git add -u

This will add all modifications (including deletes) to the index.

git add full/path/to/deleted/file

Will add the delete.

Alternatively, if you use git rm to delete files the delete operation is automatically added for you.

To get a list of deleted file names this command should work:

git status --porcelain | awk '/^ D/ {print $2}'

You could then pipe the results into xargs as Steven Penny suggested.

asm
  • 8,758
  • 3
  • 27
  • 48