'how to git commit a whole folder?
Here is a folder, which contains a lot of .java files.
How can I git commit this folder?
If I do the following commands
git add folder_name
git commit folder_name -m "commit operation"
I will see the messages nothing added to commit but untracked files present (use "git add" to track)
Solution 1:[1]
To Add a little to the above answers:
If you are wanting to commit a folder like the above
git add foldername
git commit -m "commit operation"
To add the folder you will need to be on the same level as, or above, the folder you are trying to add.
For example: App/Storage/Emails/email.php
If you are trying to add the "Storage" folder but you have been working inside it on the email.php document you will not be able to add the "Storage" folder unless you have 'changed directory' (cd ../) back up to the same level, or higher, as the Storage file itself
Solution 2:[2]
When you “add” something in Git, you add it to the staging area. When you commit, you then commit what’s in the staging area, meaning it’s possible to commit only a sub-set of changed files at any one time.
In your case, you want to add the folder to the staging area, and then just do a normal commit:
$ git add foldername
$ git commit -m 'Helpful commit message'
Solution 3:[3]
To stage an entire folder, you'd enter this command:
$git add .
The period will add all files in the folder.
Solution 4:[4]
OR, even better just the ol' "drag and drop" the folder, onto your repository opened in git browser.
Open your repository in the web portal , you will see the listing of all your files. If you have just recently created the repo, and initiated with a README, you will only see the README listing.
Open your folder which you want to upload. drag and drop on the listing in browser. See the image here.
Solution 5:[5]
I ran into the same problem. Placing a forward slash after the folder name worked for me.
ex: git add foldername/
Solution 6:[6]
Let's say I git add many folders but want to commit each folder separately, one folder per commit:
git commit -m "Updating contents of 1 folder" folder_name/\*
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Martin Bean |
| Solution 3 | kholid.nur |
| Solution 4 | RavenReema |
| Solution 5 | DevGalT |
| Solution 6 | frmbelz |
