I\'m deploying a Rails app on Heroku (for now) via git, and would also like to have a public version for people to look at. Some files are sensitive and should only be commi
Here are some other StackOverflow questions and answers along the line of "how do you do a merge while ignoring some files":
The simplest I can think of, is to use an alias
'ed merge that will remove the private files before doing the merge commit. This would work if you're willing to live with non-fast-forward merges. Here's the alias
:
git config alias.merge-master-exclude-private '!git merge --no-commit --no-ff master && (git diff --name-only HEAD..master | grep -f private_files | while read f; do git reset HEAD -- "$f"; rm -f "$f"; done; git commit -m "Merge master, excluding private files.")'
Then edit the private_files
file and add file patterns that are private; for example secret_file.*$
. You could replace private_files
in the alias with "$(git rev-parse --show-toplevel)"/private_files
to read private_files
from the top-level directory.
Use git merge-master-exclude-private
to do the merge. This will execute a non-fast-forward merge without committing, find files matching patterns in the private_files
file, reset
the index of any private files found, remove private files in the working directory, then commit. This should handle files that have whitespace in their names.
If you don't want to do the commit, giving you a chance to edit the commit message, remove -m "Merge master, excluding private files."
from the alias.
Create 2 branches. The one branch that has the private files will not be pushed to the public repo. After a merge, restore the files in question with git checkout HEAD^ -- files that should not have been merged
, rm other files
, git add -A
and git commit --amend -C HEAD
. I'm not sure what the difference in the files in question is but you get the idea. Make a small script for this and you're good to go. You could even commit a sensitive file list that you commit at the root and the script could act off of that.