I made changes to two files in different directory, How can I add the two files for a single commit. can I do like, add the first, then change the directory to second file and add the second file finally do the commit. Is this going to work?
-
2You can add as many files as you like before committing them. I suggest completing the git tutorial to gain a better understanding of the steps involved https://try.github.io/levels/1/challenges/1 – Paddyd Aug 18 '15 at 14:14
-
What error message do you get when trying to follow the procedure you're proposing? – Martin G Aug 25 '15 at 15:23
-
Yes! This is going to work! – fuz Aug 25 '15 at 15:25
5 Answers
You can add all the files using
git add file1.txt folder/file2.txt file3.txt file4.txt file5.txt
And the commit your the files you wish to commit.
git commit file1.txt folder/file2.txt file3.txt -m"I committed file1.txt folder/file2.txt"
You will have added
- file1.txt
- folder/file2.txt
- file3.txt
- file4.txt
to staging area and then commited with the same message.
- file1.txt
- folder/file2.txt
- file3.txt
Note that files are added or committed in the same format

- 848
- 10
- 29
You can use the add
command interactively:
git add -i
then you see:
*** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
What now>
hit 4 (add untracked), then you see
What now> 4
1: file1
2: file2
Add untracked>>
hit 1 and 2 to add file1
and file2
then you commit these files: git commit

- 6,280
- 3
- 26
- 47
If the two directories are part of the same git project, just add the two files with git
and then make your commit :
git add folder1/file1 folder2/file2
git commit
With doing this, you can see that for this specific commit, you have two files which the contents are changed.

- 2,899
- 1
- 17
- 33
-
1You can also add them in the same command `git add folder1/file1 folder2/file2` – Holloway Aug 18 '15 at 14:19
1."git status" list which files are staged, unstaged, and untracked. Under "Changes not staged for commit" you can see all your edited files.
git status
2."git add" to stage your commit.
git add <file1> <file2> <file3>
(or) "git add -A" to stage all the modified files to commit.
git add -A
3."git commit -m " to commit your changes,
git commit -m "I am committing multiple files"

- 875
- 1
- 12
- 36
Another option. You can add "ALL" the modified files to the next commit with
git add -A
which is equivalent to
git add -all
Then you can use
git commit -m "some info about this commit"
Useful when you have more than just two files or if you don't want to write the names/paths of them.
From:
Also this question can give to you more info about git add: Difference between "git add -A" and "git add ."