0

I'm a windows / svn person trying to learn to use GIT by command line. I'm using a basic add . /commit/push cycle, and I typically try to add all changed files, so I don't care. But every once in a while I want to add just some of the changed files. I don't enjoy typing the usually long full paths (java....) and I know I could use characters like * to match multiple files... but I found no way to know in advance what files will be affected.
As an example, if I make a git status, I got 3 files,

   modified:   myrepo/src/main/java/com/mycompany/myproject/helper/WordBuilder.java
   modified:   myrepo/src/main/java/com/mycompany/myproject/helper/WordBuyer.java
   modified:   myrepo/src/main/java/com/mycompany/myproject/helper/WordDeleter.java

I want to add just files WordBuilder and WordBuyer, so instead of typing git add . I want to type something that matches them and excludes WordDeleter (example is not great) . Lest say I want to try git add WordB*, I want to know before actually typing it what files will be added to be sure I'm not omitting or including anything by mistake.
Is this possible?
EDIT: More details I forgot: I'm using Windows7, GIT command line via msysGit/GIT for windows

Pablo Grisafi
  • 5,039
  • 1
  • 19
  • 29
  • This is not a `git` question, but rather a shell question, since `git` receives whatever list of files results from the shell's expansion of the glob. What shell are you using? (I've gotten the impression that some Windows implementations of `git` merge it and a shell into a single program, so the line between the two may be somewhat blurred). – chepner Nov 18 '13 at 13:21

2 Answers2

1

You can add --dry-run to most of git command to not doing the action, but displaying instead what will be done.

git add --dry-run WordB* should work. check with help command to check the help for others actions

Asenar
  • 6,732
  • 3
  • 36
  • 49
  • Seems to be working. I worry about the 'most of' part.... I hope the ones that does not work show an error message! thanks you! – Pablo Grisafi Nov 18 '13 at 18:31
  • yeah, "most of" because for example, --dry-run is nonsense for git fetch. But this is ok for `commit` and `add`. checks that question http://stackoverflow.com/questions/2573905/do-all-git-commands-have-a-dry-run-option for more details – Asenar Nov 19 '13 at 12:37
-1
echo WordB*

would show you the expansion without involving git.

Ian Miller
  • 593
  • 3
  • 10