How do I remove files saying “old mode 100755 new mode 100644” from unstaged changes in Git?

孤者浪人 提交于 2019-11-26 03:24:47

问题


For some reason, when I initially did a pull from the repository for a git project of mine, I got a ton of files in my working copy that have no discernible changes made to them, but keep showing up in my unstaged changes area.

I\'m using Git Gui on Windows xp, and when I go to look at the file to see what has changed. All I see is:

old mode 100755  
new mode 100644  

Does anyone know what this means?

How can I get these files out of my list of unstaged changes? (Very annoying to have to go through 100\'s of files, just to pick out files I\'ve recently edited and want to commit).


回答1:


That looks like unix file permissions modes to me (755=rwxr-xr-x, 644=rw-r--r--) - the old mode included the +x (executable) flag, the new mode doesn't.

This msysgit issue's replies suggests setting core.filemode to false in order to get rid of the issue:

git config core.filemode false



回答2:


Setting core.filemode to false does work, but make sure the settings in ~/.gitconfig aren't being overridden by those in .git/config.




回答3:


I've encountered this problem when copying a git repo with working files from an old hard drive a couple times. The problem stems from the fact that the owner and permissions changed from the old drive/machine to the new one. The long and short of it is, run the following commands to straighten things out (thanks to this superuser answer):

sudo chmod -R -x . # remove the executable bit from all files

The former command will actually resolve the differences that git diff reported, but will revoke your ability to list the directories, so ls ./ fails with ls: .: Permission denied. To fix that:

sudo chmod -R +X . # add the executable bit only for directories

The bad news is that if you do have any files you want to keep executable, such as .sh scripts, you'll need to revert those. You can do that with the following command for each file:

chmod +x ./build.sh # where build.sh is the file you want to make executable again



回答4:


It seems you have changed some permissions of the directory. I did the following steps to restore it.

$  git diff > backup-diff.txt                ### in case you have some other code changes 

$  git checkout .



回答5:


You could try git reset --hard HEAD to reset the repo to the expected default state.




回答6:


I have faced the same issue. And this save my life: https://gist.github.com/jtdp/5443498

git diff -p -R --no-color \ | grep -E "^(diff|(old|new) mode)" --color=never \ | git apply




回答7:


Usually happens when the repo is cloned between Windows and Linux/Unix machines.

Just tell git to ignore filemode change, here are several ways:

  1. Config ONLY for current repo:

    git config core.filemode false
    
  2. Config globally:

    git config --global core.filemode false
    
  3. Add in ~/.gitconfig:

    [core]
         filemode = false
    

Just select one of them.




回答8:


This happens when you pull and all files were executable in the remote repository. Making them executable again will set everything back to normal again.

chmod +x <yourfile> //For one file
chmod +x folder/* // For files in a folder

You might need to do:

chmod -x <file> // Removes execute bit

instead, for files that was not set as executable and that was changed because of the above operation. There is a better way to do this but this is just a very quick and dirty fix.




回答9:


I had just the one troublesome file with the changed permissions. To roll it back individually, I just deleted it manually with rm <file> and then did a checkout to pull a fresh copy.

Luckily I had not staged it yet.

If I had I could have run git reset -- <file> before running git checkout -- <file>




回答10:


I just ran into this issue when diffing my branch with master. Git returned one 'mode' error when I expected my branch to be identical to master. I fixed by deleting the file and then merging master in again.

First I ran the diff:

git checkout my-branch
git diff master

This returned:

diff --git a/bin/script.sh b/bin/script.sh
old mode 100755
new mode 100644

I then ran the following to fix:

rm bin/script.sh
git merge -X theirs master

After this, git diff returned no differences between my-branch and master.




回答11:


You can use the following command to change your file mode back. git add --chmod=+x -- filename Then commit to the branch.



来源:https://stackoverflow.com/questions/1257592/how-do-i-remove-files-saying-old-mode-100755-new-mode-100644-from-unstaged-cha

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!