Now I have removed 5 of those files and I want to amend these changes to the last commit.I havent pushed the commit..Am using gerrit. However when I do git status it shows me Changes not staged for commit->the 5 files which are deleted and untracked files ->which are irrelevant. I want to commit only the deletion of the 5 files and I want to ammend this to the last commit. How do i do this. When I do a git commit --amend and change the message.. The file that opens up shows me the list of untracked files as well.(as a comment ofcourse).I am scared these irrelevant untracked files will get added too. What do I do in this case? Kindly suggest. Thanks!
Asked
Active
Viewed 48 times
1 Answers
0
I am scared these irrelevant untracked files will get added too!
Untracked files are not part of the next commit.
When we run git status
, it tells us what files Git has staged for the next commit. git status
gives the following categories:
- Changes to be committed: These will be part of the next commit.
- Changes not staged for commit: These will NOT be part of the next commit.
- Untracked files: These will NOT be part of the next commit.
When we run git commit
, we see those same categories in the commit message editor. Rest assured: the commit will contain only those files that are in the changes to be committed category; it will not contain any changes not staged for commit nor any untracked files.

Shaun Luttin
- 133,272
- 81
- 405
- 467
-
I do not see any files in "changes to be committed" category. However,I wish to add files from "changes not staged for commit" to the the previous commit that I had made.How do I go about that? – user3800888 Jun 21 '17 at 03:26
-
@user3800888 You will need to run `git add` or `git rm` on the files that you would like to commit. – Shaun Luttin Jun 21 '17 at 03:28
-
wont git add the untracked files to the staging area. ? – user3800888 Jun 21 '17 at 03:48
-
@user3800888 Git will only add the files that you ask it to add. If you say `git add -A`, then it will add all the files. If you instead say `git add some-file.ext`, then it will add only that file. You get to pick and choose what to stage for commit. – Shaun Luttin Jun 21 '17 at 04:03