I can help you with that. This is a common Git pitfall.
The problem happened because when you deleted the files on the main branch and committed, you didn't undo the merge. Instead, you created a new commit that explicitly told Git, "The correct state of this branch is for these files to be deleted." When you later merged main into Internship, Git correctly applied that new "delete these files" instruction to your Internship branch.
The safest and most recommended way to fix this is to revert the commit where you deleted the files.
Step 1: Find the Commit Where You Deleted the Files
First, you need to find the hash of the specific commit where you removed the files.
Switch to your main branch:
Bash:
git checkout main
Look at the commit history to find the commit where you deleted the files. The --oneline flag makes it easier to read.
Bash:
git log --oneline
Copy the hash of that commit (in this example, e4f5g6h).
Step 2: Revert the Deletion Commit
Now, you'll create a new commit that undoes the deletion.
While still on the main branch, run the revert command with the hash you just copied:
Bash:
git revert e4f5g6h
Your code editor will open, asking you to confirm a commit message for the revert. The default message is usually fine (e.g., "Revert 'Removed internship files'"). Just save and close the editor.
Your main branch is now fixed! The files from the Internship branch have been restored.
Step 3: Update Your Internship Branch
Now you can safely bring the fixed history from main into your Internship branch.
Switch back to your Internship branch:
Bash:
git checkout Internship
Merge the corrected main branch into it:
Bash:
git merge main
Everything should now be in order. Your Internship branch has all of its latest developments, and the "deleted" files are restored. You can now continue your work and merge into main in the future without this issue.
Why This Happened: A Quick Explanation
Think of Git history as a logbook, not an editable document.
Hello,
If reverting the deletion commit on main is not an option (because the files really needed to be deleted there), one simple workaround is to create a small dummy commit.
The idea is that once main has a commit saying “delete these files”, Git will always try to apply that deletion whenever it’s merged. By adding a dummy commit (for example, editing a README or adding a temporary file) on both main and Internship, you “break the chain” of that deletion history. After that, when merging Internship into main, Git allows the Internship branch versions of the files to override the deleted ones instead of removing them again.
This way you don’t need to rewrite history, and you still get main cleaned up while preserving the latest Internship work.
Regards
Reemali