Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make git reset --hard to ignore permission changes

Tags:

git

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?

like image 665
alexandernst Avatar asked Jun 10 '13 10:06

alexandernst


People also ask

Does git reset hard remove staged changes?

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.

What git reset -- hard will do?

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.

Does git reset HEAD keep changes?

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.


1 Answers

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.

like image 56
andyg0808 Avatar answered Nov 09 '22 20:11

andyg0808