1

This is a very minor accessibility issue but I wonder if anyone has addressed it:

Whenever I do git status the files appear in alphabetical order (as they should):

❯ git status
On branch feature
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        src/source.cpp
        src/source.hpp

nothing added to commit but untracked files present (use "git add" to track)

However, I would like my headers to appear before my implementation files. One reason is that whenever I complete a bunch of work, I like to do git add -p to add stage the relevant files. It would be much nicer if I could add the headers first so that I can follow up with the implementation afterwards.

Is there some way to customize git so that I can define my own ordering of files? Something like "alphanumeric for everything before the period, then h takes precedence over everything else in the file extension."

segfault
  • 339
  • 2
  • 8

1 Answers1

1

Is your question about add -p or status? Because if you only want to add your changed header files, you can specify them via wildcard:

git add -p '**.h'

If you always want to add all your files in the same order of extensions, you can define a Git alias to simplify your life and save you some keystrokes:

git config alias.addall '!f(){ git add -p "**.hpp"; git add -p "**.cpp";};f'
knittl
  • 246,190
  • 53
  • 318
  • 364
  • Ideally both, but I mainly want it for `add -p`. If I follow your suggestion, I'd have to add all the header files, then all the implementation files. I would like to go in the following order: `x.hpp`, `x.cpp`, `y.hpp`, `y.cpp`, `z.hpp`, `z.cpp`, etc.. – segfault Jan 22 '21 at 21:17
  • @segfault: oh, I see now. You want sorted by files, but for files with identical name, you want first header, then implementation. I don't think, I have a solution for this right now – knittl Jan 22 '21 at 21:26