Is it possible to exclude specific files (*.ai, *.psd) when pushing to certain repositories with Git?
My need comes from trying to use Git for both version control and deployment to Heroku. If I include my graphic assets in the deploy, the slug size is larger than desired. However, I do need to include开发者_JS百科 all project files in my main github repository.
The easy way to solve your actual problem is to create a .slugignore
file in the root of the repository that lists files that shouldn't be packaged in the slug.
- Heroku documentation on Slugignore
You can maintain a second branch for deployment to Heroku, which contains none of those files, but still merges from master. (Of course, you'll have to work out a system for resolving the merge conflicts you get when you modify the .ai and .psd files in master).
The specific thing you ask is impossible, for the simple reason that when you push, you transfer the exact commits from one repository to another, and two commits which don't have the same tree are by definition different commits.
Tip: The most recent versions of git have a --porcelain
option for git status
which will give easy to parse information like "M file1" "DU file2" (modified and unmerged/deleted by us, respectively). You could write a git-merge wrapper for your deployment branch which attempts the merge, and automatically cleans up the expected conflicts:
git checkout deploy
if ! git merge master; then
git rm $(git status --porcelain | awk '/^DU/ {print $NF}')
fi
(The reason I printed $NF
instead of $2
is that if the file's renamed, it'll look like "DU original_name -> new_name", and the copy placed in the work tree will be new_name, not original_name.)
Of course, the script could get more complex if your situation is - you could look for only certain extensions (add them to the limiting awk pattern), or even capture the whole output in a perl script so you can easily do some more fancy logic...
There isn't a direct easy way to do that. It's certainly manageable, but with a lot of pain (git wasn't designed to do this).
It would be easier probably if you ask Heroku to provide a way to exclude some files from the deploy.
精彩评论