shunsuke_stackoverflow shunsuke_stackoverflow - 20 days ago 4
Git Question

Can't cancel my update

I have a question about git command.
I tried to cancel my update from git stash.
But i wasn't able to do it.

I use the following command.

~/xxxxx-repo on  master! ⌚ 18:27:45
$ git checkout .
~/xxxxx-repo on  master! ⌚ 18:28:02
$ git status 2.3.1
On branch master
Your branch is behind 'origin/master' by 3 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: .gitignore
modified: app/Api/Middleware/ViewSwitchMiddleware.php
modified: app/Common/Data/Api/Lib/ParamWithPaginator.php
modified: app/Common/Data/DB/Sample.php
modified: app/Common/Data/DB/User.php
modified: app/Framework/Data/CurlBasicManager.php
modified: app/Framework/Lib/ArrayObject.php
modified: app/Tool/Middleware/ViewSwitchMiddleware.php
modified: config/data.php
modified: nbproject/project.properties
modified: nbproject/project.xml
modified: public/vendor/cleditor/jquery.cleditor.css
modified: public/vendor/cleditor/jquery.cleditor.js
modified: public/vendor/cleditor/jquery.cleditor.min.js

no changes added to commit (use "git add" and/or "git commit -a")

~/xxxxx-repo on  master! ⌚ 18:28:05
$ git pull origin master 2.3.1
remote: Counting objects: 8, done.
remote:
Unpacking objects: 100% (8/8), done.
From ssh://xxxxxxx.xxxx.com/v1/repos/xxxxxx-repo
* branch master -> FETCH_HEAD
3803c7a..850eb4c master -> origin/master
Updating ee9814f..850eb4c
error: Your local changes to the following files would be overwritten by merge:
app/Framework/Data/CurlBasicManager.php
config/data.php
Please commit your changes or stash them before you merge.
Aborting


Why didn't i cancel my update?

I'm struggling this error today.

I tried to delete this repository.

Then i clone the same repository.

Then i tried the following command.

But the same error reproduced even if I have not updated any file yet.

And I tried the following way.
But I still was not able to solve my problem.

~/XXXXXXx-repo on  master! ⌚ 20:35:30
$ git add app/Framework/Data/CurlBasicManager.php 2.3.1
warning: CRLF will be replaced by LF in app/Framework/Data/CurlBasicManager.php.
The file will have its original line endings in your working directory.

~/XXXXXX-repo on  master! ⌚ 10:24:08
$ git add config/data.php 2.3.1
warning: CRLF will be replaced by LF in config/data.php.
The file will have its original line endings in your working directory.

~/XXXXX-repo on  master! ⌚ 10:24:29
$ git stash 2.3.1
warning: CRLF will be replaced by LF in .gitignore.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in app/Api/Middleware/ViewSwitchMiddleware.php.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in app/Common/Data/Api/Lib/ParamWithPaginator.php.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in app/Common/Data/DB/Sample.php.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in app/Common/Data/DB/User.php.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in app/Framework/Lib/ArrayObject.php.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in app/Tool/Middleware/ViewSwitchMiddleware.php.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in nbproject/project.properties.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in nbproject/project.xml.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in public/vendor/cleditor/jquery.cleditor.css.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in public/vendor/cleditor/jquery.cleditor.js.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in public/vendor/cleditor/jquery.cleditor.min.js.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in .gitignore.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in app/Api/Middleware/ViewSwitchMiddleware.php.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in app/Common/Data/Api/Lib/ParamWithPaginator.php.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in app/Common/Data/DB/Sample.php.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in app/Common/Data/DB/User.php.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in app/Framework/Lib/ArrayObject.php.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in app/Tool/Middleware/ViewSwitchMiddleware.php.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in nbproject/project.properties.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in nbproject/project.xml.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in public/vendor/cleditor/jquery.cleditor.css.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in public/vendor/cleditor/jquery.cleditor.js.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in public/vendor/cleditor/jquery.cleditor.min.js.
The file will have its original line endings in your working directory.
Saved working directory and index state WIP on master: ee9814f refs #4 XXXXXXXXXXXXXXXXXX
HEAD is now at ee9814f refs #4 XXXXXXXXXXXXXXXXXXXX

~/XXXXX-repo on  master! ⌚ 10:24:36
$ git pull 2.3.1
remote: Counting objects: 47, done.
remote:
Unpacking objects: 100% (47/47), done.
From ssh://XXXXXXXXXXXXXXXX/v1/repos/CandY-repo
850eb4c..2410322 master -> origin/master
Updating ee9814f..2410322
error: Your local changes to the following files would be overwritten by merge:
app/Framework/Data/CurlBasicManager.php
config/data.php
Please commit your changes or stash them before you merge.
Aborting


I'm still struggling...

Answer

Why didn't i cancel my update?

git checkout . gets files from the index and restore them to the working directory. Your modifications were already staged (i.e. in the index), so you needed to git checkout HEAD . to discard them.

Regarding the problem, you set core.autocrlf to true, right? It's a config to be used when you're on Windows and working on a repo made in Unix. So it's not for you. This config converts CRLF to LF when add, which is probably the cause of the issue. You can set core.autocrlf to false by:

git config --local core.autocrlf false

Also run it with --global instead of --local if you want the config globally.