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?
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.
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
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"
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
to staging area and then commited with the same message.
Note that files are added or committed in the same format
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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.