How do I force an overwrite of local files on a git pull
?
The scenario is the following:
First of all, try the standard way:
git reset HEAD --hard # To remove all not committed changes!
git clean -fd # To remove all untracked (non-git) files and folders!
Warning: Above commands can results in data/files loss only if you don't have them committed! If you're not sure, make the backup first of your whole repository folder.
Then pull it again.
If above won't help and you don't care about your untracked files/directories (make the backup first just in case), try the following simple steps:
cd your_git_repo # where 'your_git_repo' is your git repository folder
rm -rfv * # WARNING: only run inside your git repository!
git pull # pull the sources again
This will REMOVE all git files (excempt .git/
dir, where you have all commits) and pull it again.
Why git reset HEAD --hard
could fail in some cases?
Custom rules in .gitattributes file
Having eol=lf
rule in .gitattributes could cause git to modify some file changes by converting CRLF line-endings into LF in some text files.
If that's the case, you've to commit these CRLF/LF changes (by reviewing them in git status
), or try: git config core.autcrlf false
to temporary ignore them.
File system incompability
When you're using file-system which doesn't support permission attributes.
In example you have two repositories, one on Linux/Mac (ext3
/hfs+
) and another one on FAT32/NTFS based file-system.
As you notice, there are two different kind of file systems, so the one which doesn't support Unix permissions basically can't reset file permissions on system which doesn't support that kind of permissions, so no matter how --hard
you try, git always detect some "changes".