Can a file be both staged and unstaged in Git?

后端 未结 4 1860
挽巷
挽巷 2021-01-31 10:56

While working on another file, I edited README.md and then ran git add README.md. When doing a git commit, I see that README.md is both i

4条回答
  •  野的像风
    2021-01-31 11:39

    Answer to "Does this make sense?"

    It only makes sense if you understand that git does not store differences it stores snapshots.

    In the example you describe there are two versions of README.md in your changes. The staged one is the version that you're currently happy with and will end up being the latest snapshot of the file if you choose to commit it. The unstaged version is is a potential snapshot that will replace the currently staged version if you choose to stage it.

    Read the section 'Snapshots, Not Differences' in the following link for more understanding on how git works:

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

    Also look at the following link for a further explanation of the scenario that you've included in your question (in particular the section 'Staging Modified Files'):

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

提交回复
热议问题