Commit changes only in one directory in Git

I'm using Git 1.7.4.1 on Mac 10.6.6. From the command line, how do I commit changes in only a single directory? I added the directory by doing:

git add my-dir

but doing

git commit -a

brings up a list of all changes in my repo, and I only want to commit and push changes from my-dir .


Omit the -a option. Then git will commit only the files that you staged with git add .

You can also try committing the directory without staging with git commit my-dir .


Why does no one mention you can simply

git commit -m 'message' -- my-dir

It seems to me the OP isn't used to / doesn't like to use the staging area directly. This approach is also a lot safer to recommend without further context, because chances are that a defaault commit (of everything that's staged) will

  • commit more than just my-dir if it already had been staged
  • will produce confusing results when the OP is not used to managing the staging area explicitly (because the working tree can have gotten out of synch with the index)

  • Hmm, odd. The following should work. Assuming you have nothing staged.

    git add my-dir
    git commit -m "Commiting first revision of my-dir folder. Very exciting feature!"
    git push origin master
    
    链接地址: http://www.djcxy.com/p/6170.html

    上一篇: 检出已在工作树中移动的多个文件

    下一篇: 仅在Git中的一个目录中提交更改