git add - Which plumbing commands achieve the same as git add? -


i'd understand better learning happens when entering

git add $directory 

and

git add $file 

how work?

a rough idea can gained reading progit's git internals section.

  • if $directory directory, find $directory -type f -exec git add {} \;, i.e. recursively adding files in $directory. then, git add $filename applies each file.
  • a check against .gitignore (and "superiors")
  • a check against .gitattributes, running clean filter if applicable
  • git hash-object -w cleaned contents

and then, index gets updates somehow, involves git mktree. happens there? tree directory contain files added or files committed well? , happens next?

git add not have single equivalent plumbing command, closest 1 git update-index. progit description correct:

  1. replace each directory list of directory's contents. result list of files specified add, special case handling files known not in directory (i.e., removed), , files special index states (--assume-unchanged , --skip-worktree). in other words, step consults current index.

  2. check unstaged-but-ignored (via .gitignore) files , discard them list (with warning) unless given -f / --force.

    (side note: have not tested on subdirectories, , it's possible -f won't apply subdirectory entry picked recursive scan, names given on command line. if that's case, step 2 must combined step 1, names don't added if we're going ignore them -f.)

  3. apply attributes if any, making temporary cleaned copies of files if needed.

  4. use git update-index --add --remove --replace modified files written repository, index entries updated, including mode updates. (for files cleaned in step 3, have use separate git hash-object -w, suggested, , --index-info instead of --add --remove --replace.)

the git mktree command not enter process @ all, index flat file using poorly-documented format (or more precisely, 1 of several formats; see --index-version).

the index allows 4 entries per file name, called stages: stage 0 normal cache entry, , stages 1 through 3 conflicted merges. there several special bits marking files removed, or --assume-unchanged, --skip-worktree, --intent-to-add, , special internal use flags, and—even though git not store directories—there index entries directories (which let git @ ctime field of directory, lets git skip unmodified directories quickly, provided can trust os maintain this).

the git mktree command comes play when converting index series of tree objects. git must make 1 tree each subdirectory in index, plus 1 top level tree representing overall index. (subprojects, if exist, in index "gitlink" entries, how appear within whatever tree contains them.)


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -