Rather that trying to safely synchronize files between branches, including hidden files, avoiding the .git
dir, and removing excess
files, it is possible to ask git to create a new commit that represents the exact file set of another commit.
This is based on the concept that git commits are just a pointer to a tree object representing the state of all the files in the repository at the moment of the commit. Instead of creating a new commit based on our git workspace, we create a commit based on the tree from another commit.
# find the tree ID of the source commit
git cat-file -p ${source_commit} | grep tree