Why does 'git commit' not save my changes?

前端 未结 12 1533
星月不相逢
星月不相逢 2020-11-29 15:16

I did a git commit -m \"message\" like this:

> git commit -m \"save arezzo files\"
# On branch master
# Changes not staged for commit:
#   (u         


        
相关标签:
12条回答
  • 2020-11-29 15:30

    I had an issue where I was doing commit --amend even after issuing a git add . and it still wasn't working. Turns out I made some .vimrc customizations and my editor wasn't working correctly. Fixing these errors so that vim returns the correct code resolved the issue.

    0 讨论(0)
  • 2020-11-29 15:32

    I had a very similar issue with the same error message. "Changes not staged for commit", yet when I do a diff it shows differences. I finally figured out that a while back I had changed a directories case. ex. "PostgeSQL" to "postgresql". As I remember now sometimes git will leave a file or two behind in the old case directory. Then you will commit a new version to the new case.

    Thus git doesn't know which one to rely on. So to resolve it, I had to go onto the github's website. Then you're able to view both cases. And you must delete all the files in the incorrect cased directory. Be sure that you have the correct version saved off or in the correct cased directory.

    Once you have deleted all the files in the old case directory, that whole directory will disappear. Then do a commit.

    At this point you should be able to do a Pull on your local computer and not see the conflicts any more. Thus being able to commit again. :)

    0 讨论(0)
  • 2020-11-29 15:36

    The reason why this is happening is because you have a folder that is already being tracked by Git inside another folder that is also tracked by Git. For example, I had a project and I added a subfolder to it. Both of them were being tracked by Git before I put one inside the other. In order to stop tracking the one inside, find it and remove the Git file with:

    rm -rf .git
    

    In my case I had a WordPress application and the folder I added inside was a theme. So I had to go to the theme root, and remove the Git file, so that the whole project would now be tracked by the parent, the WordPress application.

    0 讨论(0)
  • 2020-11-29 15:37

    if you have a subfolder, which was cloned from other git-Repository, first you have to remove the $.git$ file from the child-Repository: rm -rf .git after that you can change to parent folder and use git add -A.

    0 讨论(0)
  • 2020-11-29 15:38

    I find this problem appearing when I've done a git add . in a subdirectory below where my .gitignore file lives (the home directory of my repository, so to speak). Try changing directories to your uppermost directory and running git add . followed by git commit -m "my commit message".

    0 讨论(0)
  • 2020-11-29 15:40

    As the message says:

    no changes added to commit (use "git add" and/or "git commit -a")

    Git has a "staging area" where files need to be added before being committed, you can read an explanation of it here.


    For your specific example, you can use:

    git commit -am "save arezzo files"
    

    (note the extra a in the flags, can also be written as git commit -a -m "message" - both do the same thing)

    Alternatively, if you want to be more selective about what you add to the commit, you use the git add command to add the appropriate files to the staging area, and git status to preview what is about to be added (remembering to pay attention to the wording used).

    You can also find general documentation and tutorials for how to use git on the git documentation page which will give more detail about the concept of staging/adding files.


    One other thing worth knowing about is interactive staging - this allows you to add parts of a file to the staging area, so if you've made three distinct code changes (for related but different functionality), you can use interactive mode to split the changes and add/commit each part in turn. Having smaller specific commits like this can be helpful.

    0 讨论(0)
提交回复
热议问题