I'm trying to git reset --hard origin/master
but make git somehow checkout the files only if the actual content of each file changed, instead of checking them even if only the permissions changed.
Is there some parameter I can pass to git reset or that's a thing that can be solved only with a script?
Git Reset A Specific File The changes it contains will still be present in the working directory. The --soft , --mixed , and --hard flags do not have any effect on the file-level version of git reset , as the staged snapshot is always updated, and the working directory is never updated.
In addition to unstaging changes, the --hard flag tells Git to overwrite all changes in the working directory, too. Put another way: this obliterates all uncommitted changes, so make sure you really want to throw away your local developments before using it.
They all rewrite Git history, and they all move the HEAD back, but they deal with the changes differently: git reset --soft , which will keep your files, and stage all changes back automatically. git reset --hard , which will completely destroy any changes and remove them from the local directory.
Try setting core.fileMode
to false
as described here (docs) (git config core.fileMode false
should do the trick). This seems to make Git ignore any permission changes when hard resetting. Now, I did find that if Git couldn't read the file (e.g., I'd set the permissions to 000), a hard reset would restore the original permissions it was committed with.
Another thought, which might be of interest, would be to write a hook which would set the permissions of all files in the repo to whatever you wanted. That might also give you some assurance that you weren't accidentally leaving a new file with dangerous permissions.
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