![]() ![]() The real question is what goes into commits, and that's determined, as we just noted, by what is in the index. Ignoring is more of a side effect than anything else. gitignore is the wrong name for this file, because it's not really a list of files, or even glob patterns, to ignore. gitignore do? (More about untracked files) Commands that seem to change something, like git commit -amend or git rebase, actually fake it: they make new commits, leaving the old ones in place, undisturbed, but then pull a stage-magician's trick, using smoke and mirrors to make it appear as though the new ones have replaced the old ones. In fact, Git can't change any object (commit, tree, file, or annotated tag), by design. No existing commit is ever changed by any new commit. Making the new commit causes the current branch to extend by one commit, so that the branch name points to the new commit you just made. Whatever is in the index, becomes what is in that commit. You git add and git rm files to update the index, and then you git commit to turn the index contents-the set of all tracked files-into a new commit. In summary, though, the index is what will go into the next commit you make. The file data-the actual contents of each file-are kept in Git's objects, inside the repository.) The index actually stores only the file hash IDs. Merging uses stages 1, 2, and 3, while normal operation uses only stage zero. These are called "stage numbers", and Git only ever uses at most three stage numbers per file. In fact, for each file, the index has up to four slots, rather than just one slot. (And, of course, the index has that special role in merges. So the index not only speeds up git commit, it also speeds up git checkout.ġThis gets complicated by things like core.eol settings and what Git calls smudge filters, so let's ignore those. It only needs to change out files that are different-or, of course, remove files that are in the current commit but not in the to-be-checked-out commit, or add new files that are not in the current commit but are in the to-be-checked-out commit. 1 It also means that if you now run git checkout dev or git checkout feature or git checkout master, Git can switch to that commit on that branch by comparing that commit's files to those in the current index. This means that after you make a commit, the index matches the commit exactly. What Git does instead is to "pre-prepare" each commit: the index holds the next commit at all times. Many other version control systems do not have an index at all, and instead construct something much like it at commit-time by scanning every file. The index has a big and very special role in merges, but ignoring that, the index mainly serves as a way for Git to stage "the next commit" one piece at a time, so that git commit itself is very fast. ![]() gitignore (in which case it adds a "to be removed" index entry and removes the work-tree file). gitignore at all, in any way-unless, of course, you run git rm. That is, it removes (with a delayed removal) the file from the index: for each file given as an argument, it writes an entry into the index that says "when the next commit gets made, leave this file out of that commit." That is, the file is still tracked for the moment, but as a special "so as to become deleted" rather than "generally tracked". When you add -cached (as in git rm -cached file1 dir/file2), Git only does the first step, skipping the second step. For technical reasons, it writes a "to be removed" entry into the index, instead of just removing the index entry. It removes a file from the index-except this removal gets delayed. The git rm command does two things by default: The short (and not 100% accurate but close enough) answer to this is that a file is tracked if it is in the index. Dirn's answer is correct, so this is a bit redundant, and there are plenty of other questions about both git rm and what it means for a file to be tracked or ignored, but based on comments, I think this might be a better way to explain these several items: What does it mean for a file to be tracked or untracked? ![]()
0 Comments
Leave a Reply. |