简体   繁体   中英

Why can't I pull/rebase my Git repository?

I have a local Git repository, which I'm trying to sync with the remote one. There is one binary file, which I didn't touch. But I can't rebase, for some weird reason:

git config --local core.autocrlf false
git reset --hard --quiet
git clean --force -d
git fetch --quiet
git checkout master
Already on "master"
git rebase --abort
git stash 
warning: CRLF will be replaced by LF in test_assets/favicon.ico.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in test_assets/favicon.ico.
The file will have its original line endings in your working directory.
git rebase --strategy-option=theirs origin/master
Cannot rebase: You have unstaged changes.
Please commit or stash them.

M   test_assets/favicon.ico

What can I do?

A favicon.ico file is generally a binary file . Your Git warnings:

 warning: CRLF will be replaced by LF in test_assets/favicon.ico. 

tell us that you have—probably unintentionally—instructed your Git to treat it as a text file.

Git is therefore modifying the file, per your instructions, when it comes out of the repository. That's why it shows up as modified, and why you cannot merge or rebase until you commit the changes you're telling Git you want.

The solution is to stop telling Git that this file is text. It's a bit hard to say for sure where you tell Git that this file is text, since there are multiple mechanisms for these things, but if you have a .gitattributes file, you can use that to tell Git that this file, and indeed any file named *.ico , is definitely not text, by adding the line:

*.ico   -text

to that .gitattributes file (which you can then git add and git commit to make a new commit that has the updated .gitattributes ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM