本地大体积Git仓库如何单独推送提交中的子文件夹?
Got it, let's break this down simply—since your 30GB dataset is too big to handle all at once, you can split the process into smaller chunks by committing and pushing each subfolder individually. Here's exactly how to do it:
Step 1: Prepare your repository (if not already done)
If you haven't initialized your local Git repo yet, start with:
git init git remote add origin "your-github-repo-url"
(Skip this if you've already run these commands.)
Step 2: Commit and push each subfolder one by one
For each subfolder (let's use dataset-folder-1, dataset-folder-2 as examples):
Stage only the target subfolder:
git add dataset-folder-1/The trailing slash ensures you're adding all contents of the folder, not just the folder itself (though Git handles this either way, it's a clear habit to form).
Commit the staged folder with a descriptive message:
git commit -m "Add dataset subfolder: dataset-folder-1"Using specific messages helps track which parts of the dataset were added when.
Push this single commit to GitHub:
git push origin masterThis will only send the contents of the subfolder you just committed—no need to process the entire 30GB at once.
Repeat these three steps for every subfolder in your repository.
Important Notes
- If you accidentally ran
git add .(staged all files) already, undo the staging first with:
This clears all staged changes so you can start staging individual folders.git reset - If your remote repo already has existing content, you may need to run
git pull origin masterbefore pushing to avoid conflicts (though this shouldn't be an issue if you're setting up a new repo). - If even individual subfolders are still too large (e.g., 10GB each), consider using Git LFS (Large File Storage) to handle large files more efficiently—but that's a separate workflow. For now, splitting by subfolders should solve your laptop crashing issue.
内容的提问来源于stack exchange,提问作者Atena

