Git-add does not work with wildcards

I am trying to add (edit: DELETE operation) these files with the text "generated" in it and it does not work. I am 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 create anything. However, the file works by file.

+1
source share
3 answers

Perhaps it is, good sir

 find | grep generated.cs | xargs git add 
+2
source

There seem to be two minor issues with your team

  • It seems that the files you want to stage are the directory from which the shell is located, so you need to add a leading * .
  • You want to remove files that have been deleted. There are two ways to do this by calling git rm <file name> in each deleted file or using the -u flag of the add command. From the documentation (my emphasis):

    -u
    --update
    Only a match with already tracked files in the index, and not with the working tree. This means that it will never create new files, but it will process the changed new contents of the monitored files and that it will delete the files from the index if the corresponding files in the working tree were deleted .

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

+2
source

The problem is that wildcards will only expand to the names of files located on the file system (since the shell performs the extension, not git ). Since you deleted the files, they are not in the file system, so you need another command. There are two easy ways to add a delete operation.

 git add -u 

This will add all changes (including deletions) to the index.

 git add full/path/to/deleted/file 

Deletion will be added.

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 can then pass the results to xargs , as Stephen Penny suggested.

0
source

Source: https://habr.com/ru/post/1469360/


All Articles