Celeritas
Celeritas

Reputation: 15033

Commiting changes for specific files that were changed but not others

I am working on a project.I added a new file to the project, then modified two existing ones. I would like to push a commit for the two changed files, so that I could write a separate commit message for the newly created file. This is what I tried:

  1. omitted my usual step of git add . as I didn't want the new file added just yet
  2. git commit -m "changed files to excluded case..." but got message about "Changes not staged for commit" and "Untracked files"
  3. git push origin master but got Everything up to date, however nothing was changed on the remote when I checked it manually.

How best to proceed?

Upvotes: 0

Views: 17

Answers (1)

axiac
axiac

Reputation: 72177

committed my usual step of git add . as I didn't want the new file added just yet

On the contrary, git add . adds all the changes (new files, updated files, deleted files) from the current directory and its subdirectories to the index.

From the output of the other two commands it seems you forgot about git add (or ran it into a directory of the project where nothing changed). git commit didn't create a new commit because there were no changes staged for it, git push reported that everything is up to date because you didn't create a new commit (and it also has no work to do).

In order to get the outcome you expect you need to be more specific when you use git add.

Use git status first to learn about the current status of the working tree (what files were added/modified/deleted) and of the index (what changes were already staged for the next commit).

Then use git add and provide it the paths of the files you want to stage for commit. In your case, use it (once or several times) with the paths of the modified files but not with the path of the new file.

Use git status as often as needed to know exactly what will go into the next commit.

Upvotes: 1

Related Questions