Can a file be both staged and unstaged in Git?

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

    Actually the state you see is very easily to reproduce:

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

    in #1 we stage the empty test file. #2 changes the contents of the file. These changes will no be staged (since you need to explicitly stage changes using git add). The output of git status in #3 tells you exactly that.

    To see which changes have been staged, run git diff --cached. To see which changes to your working copy files have not been staged, run git diff.

    In your question you state that you ran git commit. From your git status output it seems as if the commit was not created, probably 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 the commit!

提交回复
热议问题