Search code examples
gitgit-commit

How to add multiple files in git for a single commit?


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?


Solution

  • 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