0

I'm trying to use git update-index --again to re-add modified files to the index. This works fine, but only for files/directories in the current directory. Is this expected behavior for this command or is there any option to make it consider the whole repository?

planetp
  • 14,248
  • 20
  • 86
  • 160

2 Answers2

0

This appears (in my tests) to work just like any typical git command. That is, it defaults to the current working directory and subdirectories (recursively), and you can specify paths if you want something different. If that's not the behavior you're seeing, please clarify with more specifics and I can take another look at it.

So for example

# setup a repo with some files
git init
touch file1
touch file2
mkdir dir
touch dir/file3
touch dir/file4
git add .
git commit -m "1"

# stage changes for a couple of the files, and make some additional changes
echo foo >file1
git add file1
echo bar >> file1
echo foo > file2
cd dir
echo foo >> file3
git add file3
git echo bar >> file3
git echo foo > file4

# now try it...
git update-index --again

Becuse we're in the dir directory, the default (like with most git commands that take paths) is to default to the current directory. So only file3 is re-staged - not file1. But if we said

git update-index --again :/:

this will apply the command from the root of the worktree.

planetp
  • 14,248
  • 20
  • 86
  • 160
Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • This works, thanks! Could you explain what `:/:` is? Where is it documented? – planetp Jan 21 '21 at 20:57
  • `:/:` is a shorthand pathspec that emans "the root directory of the repo". It can also be spelled `:(top)` It is documented in the `pathspec` entry of the git glossary (https://git-scm.com/docs/gitglossary). (Possibly elsewhere as well, but that's the first canonical source I could find.) – Mark Adelsberger Jan 21 '21 at 23:44
0

As a note, one way to run git commands from the top of the work tree is to add an alias that gets it done there:

git config --global alias.attop '!git'

and then you can git attop update-index --again, I also have !true; as an alias so I can git exec anycommand to run find or whatever at the top of the work tree.

jthill
  • 55,082
  • 5
  • 77
  • 137