Git合并后两分支仍存差异,如何将缺失文件同步至master分支?
Hey there! Let’s work through this problem together. It’s super common to run into missing files after a branch merge—usually it’s because some files weren’t tracked in Git, or the merge process didn’t pick them up for some reason. Here’s how you can sync those 40 missing files from develop to master and get your branch structure back on track:
First, let’s confirm the full list of files that exist in develop but not in master. Run this command in your repo:
git diff master develop --name-only
This will spit out a clean list of all files that differ between the two branches. Jot this down (or save it to a text file) so you know exactly what you’re dealing with.
develop Sometimes files go missing because they were never added to Git in the first place. Let’s verify this by switching to develop and checking the repo status:
git checkout develop git status
If you see the missing files listed under Untracked files, that’s the issue! Git doesn’t merge untracked files, so we need to add them to develop first:
# Add specific files, or use . to add all untracked (be careful!) git add path/to/missing/file1 path/to/missing/file2 git commit -m "Track missing files that belong in develop"
develop into master Now switch back to master and run the merge again. This time, Git will recognize the newly tracked files and bring them over:
git checkout master git merge develop
If you hit any new conflicts, resolve them like you did before—no surprises here.
If the missing files were already tracked in develop but still didn’t make it to master, we can directly copy them over from develop:
# Make sure you're on master first git checkout master # Copy the missing files from develop to master git checkout develop -- path/to/missing/file1 path/to/missing/file2 # Commit the changes git add path/to/missing/file1 path/to/missing/file2 git commit -m "Sync tracked missing files from develop to master"
Once you’re done, double-check that all differences are gone with the same diff command from Step 1:
git diff master develop --name-only
If the output is empty, congratulations—master and develop now have matching file sets!
A quick heads-up: Before making any big changes, it’s always a good idea to create a temporary test branch (like master-test) to run these steps on first. That way you can avoid messing up your main master branch if something goes sideways.
内容的提问来源于stack exchange,提问作者Patrick Na

