无法取消我的更新

Can't cancel my update

我有一个关于 git 命令的问题。 我试图从 git stash 取消我的更新。 但是我做不到。

我使用下面的命令。

    ~/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

为什么我没有取消我的更新?

我今天遇到这个错误。

我试图删除这个存储库。

然后我克隆同一个存储库。

然后我尝试了以下命令。

但即使我还没有更新任何文件,同样的错误也会重现。

然后我尝试了以下方法。 但是还是没能解决我的问题。

      ~/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

我还在挣扎...

问题已更新,现在似乎有几个问题。

不同的操作系统使用不同的行尾。

Git 可以配置为不理会它们,这样就不会每次都尝试更改它们。更多关于这个问题和答案:How to change line-ending settings

另一个问题可能是相关文件未被跟踪,因此没有被隐藏。

git add app/Framework/Data/CurlBasicManager.php
git add config/data.php

然后

git stash

那你就可以git pull.

gitstatus 的输出总是会解释发生了什么。

Why didn't i cancel my update?

git checkout . 从索引中获取文件并将它们恢复到工作目录。 您的修改已经上演(即在索引中),因此您需要 git checkout HEAD . 丢弃它们。

关于这个问题,你把core.autocrlf设置为true,对吧? 当您在 Windows 上并处理在 Unix 中创建的 repo 时,它是一个配置。所以它不适合你。 此配置在添加时将 CRLF 转换为 LF,这可能是问题的原因。 您可以通过以下方式将 core.autocrlf 设置为 false:

git config --local core.autocrlf false

另外 运行 使用 --global 而不是 --local 如果你想要全局配置。