Can a file be both staged and unstaged in Git?

后端 未结 4 1859
挽巷
挽巷 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:55

    Where in .git could I look to see the authoritative state of this file?

    Use git diff:

    • git diff -- yourFile will give you the changes not yet staged (not yet added to the index)
    • git diff --cached -- yourFile will give you the changes already added to the index.

    See more at "Changes, not files":

    Most version control systems work with files. You add the file to source control and the system tracks changes from that moment on.

    Git concentrates on the changes to a file, not the file itself.
    A git add file command does not tell git to add the file to the repository, but to note the current state of the file for it to be committed later.

    See also "git add -p: The most powerful git feature you're not using yet"


    Note that git status -v -v will soon (Git 2.3.4, Q2 2015) shows you both diffs (staged and unstaged), possible listing different diffs for the same file.

    See "Show both staged & working tree in git diff?".

提交回复
热议问题