Can a file be delivered and not installed in Git?

While working on another file, I edited README.md and then ran git add README.md . When I commit git, I see that README.md is both “Changes to be committed” and “Changes not committed to commit”.

It makes sense? Where in .git can I see how this is the authoritative state of this file?
 # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: README.md # modified: utils/arrterm # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: README.md 
+8
git version-control
source share
4 answers

This means that some of the changes you made are organized for fixing, and some are not.

You can check what is delivered if you run

 git diff --staged -- README.md 

and check what is not installed by running

 git diff -- README.md 

Most version control systems typically save changes between two states. The git method works, while you make several changes to the file, you will need to add / tag each of them to be part of the same aka a commit change set. When you use git add , this is done automatically.

However, this is not the only way to add all your individual changes (hunks) to your index. You can, for example, make several changes to the same file and commit them in different commits or add only certain changes to the commit. For example. to explicitly add some changes to your "index", but not others, you can do this using git add -p to add only some "hunks" (groups) of changes, and not the entire list of changes themselves.

What happened is that the changes you made in README.md before ( git add ) will be displayed in order and any changes you made after t24> will be displayed as uninstalled, as you received above.

+10
source share

Where in .git can I see how this is the authoritative state of this file?

Use git diff :

  • git diff -- yourFile will provide you with changes that have not yet been put (not yet added to the index)
  • git diff --cached -- yourFile will provide you with the changes already added to the index.

More details in the section Changes, not files ":

Most version control systems work with files. You add the file to the original control, and the system tracks the changes from now on.

Git focuses on file changes, not the file itself .
The git add file command does not tell git to add the file to the repository, but pay attention to the current state of the file, which will be executed later.

See also " git add -p : the most powerful git function you don't use yet


Please note that the status of git status -v -v will soon (Git 2.3.4, Q2 2015) show you both diff (phased and non-static), it is possible to list various differences for the same file.

See " Show both old and working tree in git diff? ".

+7
source share

In fact, the state you see is very easy to reproduce:

 git init touch test git add test #1 echo 42 > test #2 git status #3 

at # 1 we put an empty test file. # 2 changes the contents of a file. These changes will not be organized (since you need to explicitly push changes using git add ). The output of git status in # 3 tells you exactly that.

To find out what changes have been made, run git diff --cached . To find out what changes in your working copy files were not made, run git diff .

In your question, say you run git commit . From your git status output, it seems that the commit has not been created, possibly because you did not enter a commit message. Check the output of git commit , git probably told you what went wrong when trying to create a commit!

+1
source share

Answer "Does this make sense?"

This makes sense if you understand that git does not preserve the differences stored by snapshots.

In the example you are describing, there are two versions of README.md in your changes. The phased option is the version you are currently happy with, and will ultimately be the last snapshot of the file if you decide to commit it. An uninstalled version is a potential snapshot that will replace the current phased version if you decide to execute it.

Read the “Snapshots, Not Differences” section in the following link to find out how git works:

http://git-scm.com/book/en/Getting-Started-Git-Basics

Also check out the following link for a further explanation of the script that you included in your question (in particular, the “Splitting Modified Files” section):

http://git-scm.com/book/en/Git-Basics-Recording-Changes-to-the-Repository

+1
source share

All Articles