Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commit changes only in one directory in Git

Tags:

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.

like image 967
Dave Avatar asked May 02 '11 20:05

Dave


People also ask

How do I commit a directory in git?

Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.

How do you exclude a file from a commit?

Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.


1 Answers

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)
like image 197
sehe Avatar answered Nov 03 '22 00:11

sehe