You were on the right track, and there are multiple ways to fix this. Conceptually, an easy way that is guaranteed to work is:
- Check out the latest commit that had the files.
- Copy the files outside of the repo.
- Check out
master (to the HEAD commit).
- Copy the files from outside the repo back where you want them.
- The files will appear as added files. Stage them and commit.
A more "Gitty" way to achieve the same thing would be to revert the commit that deleted the files. If the only thing that commit did was delete the files, then the solution is a one-liner:
git revert <commit-id-that-deleted-the-files>
This will create a new commit that undoes the specified commit, effectively doing the identical multi-step process described above, but in a single command.
If the commit did other things too, then you could do a partial revert, like this:
git revert <commit-id-that-deleted-the-files> --no-commit
# Now unstage all files except the two files you are "undeleting"
# commit the change
git commit # Adjust the commit message appropriately
# Now undo any other pending changes leftover from the revert
git reset --hard HEAD
If you use the revert command, Git proposes a useful commit message. However, if you modify the revert in some way, I recommend modifying the commit message like this:
Partial Revert "Previous commit message..."
This commit only reverts the deletion of files X and Y.
This reverts commit <commit-id-that-deleted-the-files>.
By the way, the reason your merge didn't work is because as described, the merge didn't do anything. When you merge, you only bring in commits that aren't already on your branch. The new branch you made was on the same commit ID and was already in your branch, so the merge had no effect. You may have even seen the response: "Already up to date."