I have a production git repo that I only pull changes from the main repo into; I never change this repo or do commits/pushes from here. I recently accidentally pushed some untracked (at least I thought they were) image files to the main repo from my local dev repo. Now when I try to pull the latest from the main repo, git reports an error regarding overwriting the exiting image file with the file from the main repo. I don't even want this file from the repo (it's located in a ,gitignored directory on the production repo)
How can I a) get rid of these unwanted image files in my main repo, or b) exclude these files from my git pull?
To exclude certain files from appearing in pull requests: In the repository containing the pull request, click Repository settings > Excluded files in the Pull Requests section. In the Patterns field, enter patterns to exclude from pull request diff views. Click Save.
If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.
git checkout origin/master -- path/to/file // git checkout / -- path/to/file will checkout the particular file from the downloaded changes (origin/master). That's it!
Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.
This allowed me to tell git to ignore a specific file, even though it was already part of a project. All changes I make to it will be ignored:
git update-index --assume-unchanged Localization/el-GR.js
Source: http://codethug.com/2013/09/20/4-ways-to-ignore-files-with-git/
git pull
is equivalent (almost) to git fetch && git merge
. You just have to invoke fetch and than merge only specific files - tutorial.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With