user12408331
user12408331

Reputation:

What can git-add do that git update-index can't?

From the research I've come across, they both seem to do the same thing. From the git documentation, git-add adds the file contents to the index while git update-index 'registers' it. Not sure what is meant by register and how that differs from add.

Upvotes: 0

Views: 75

Answers (1)

torek
torek

Reputation: 487983

As a user-facing (or porcelain) command, git add has a lot of user-oriented features, including:

  • Pathspec arguments: git update-index does not use or accept pathspecs, but git add does, so git add :(attr:text)/ would add only files marked specifically "text" in .gitattributes, for instance.
  • The options -a, -A, --ignore-removal, -u, and so on.
  • An interactive mode (which I never use and have never gotten the hang of).
  • The --patch or -p option, which invokes a separate Perl program that creates a diff between the index and work-tree copies of a file and lets you pick and choose parts of that diff to apply to the index.

There are no doubt additional things not covered here, and will be more over time. Meanwhile, as a plumbing command, git update-index has abilities that are not suitable for direct use by humans, such as the ability to put files into particular staging slots.

Upvotes: 2

Related Questions