How are files stored in the git folder?

I would like to understand what Git is actually stored when moving files to the "intermediate" state.

Consider the following sequence:

A new file is added and committed to the local repository:

touch file.txt git add file.txt git commit 

I am making changes to the file:

 echo text1 > file.txt git add file.txt 

Then I edit the file again before committing it:

 echo text2 > file.txt 

A git status shows:

 # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: file.txt # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: file.txt # 

Then I commit the file:

 git commit file.txt 

How does Git handle the new, second update of file.txt without the knowledge? The "status" output looks as if he tried to check the first revision, but without saving the uninstalled changes, without checking them.

Is there an implicit step that is performed in this case?

+8
git
source share
2 answers

Think of Git as two things - take (snapshots of files) and shortcuts (by the way, branches).

Git actually creates a commit when you git add , not when you git commit . Therefore, when you executed git add in the modified file, it created a commit with these changes and assigned the label “intermediate” to that particular commit.

When you changed the file again before executing git commit , it now has a “step commit” (on which git commit has not been executed yet), and new changes to the file that have not been added and have not been committed. The way git status can show you both.

When you git commit , it actually moves your current branch label to a specific commit (and removes the "intermediate" label), so the commit is no longer marked as "setting", but you are currently in the "master" (or any branch)).

+7
source share

git commit <somefiles> equivalent to git add <somefiles> followed by git commit . If you just do a git commit , git will make all the incremental changes, but it won’t make the changes since the last start of the file in question.

+4
source share

All Articles