Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I made changes to two files in a 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 the second file and add the second file finally do the commit. Is this going to work?

2 Answers

+1 vote
by (62.9k points)

You can add all the files using the git add command like below for all the files you want to add, which will add all your files to the staging area, which means the files are ready to be committed.

git add file1.txt folder/file2.txt file3.txt file4.txt file5.txt

Now commit your files, the editions or addition made in the files will now be saved.

git commit file1.txt folder/file2.txt file3.txt -m "Some_message"

You will have added these files

file1.txt

folder/file2.txt

file3.txt

file4.txt

to the staging area and then committed with the same message.

file1.txt

folder/file2.txt

file3.txt

Note that files are added or committed in the same format.

git add multiple files-How to add multiple files in git for a single commit?
Intellipaat-community
by (19.7k points)
Thanks, finally now I know how to add two files for a single commit
0 votes
by (2.8k points)

You can do it by adding the path of that particular file, but before making a commit you need to stage them as well,
 

To stage multiple files:

git add file1.txt folder/file2.txt file3.txt file4.txt file5.txt 

To commit multiple files:

git commit file1.txt folder/file2.txt file3.txt -m "Some_message"

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...