简体   繁体   English

无法取消我的更新

[英]Can't cancel my update

I have a question about git command. 我对git命令有疑问。 I tried to cancel my update from git stash. 我试图从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... 我还在努力...

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 (ie in the index), so you needed to git checkout HEAD . 您的修改已经进行(即在索引中),因此您需要git checkout HEAD . to discard them. 丢弃它们。

Regarding the problem, you set core.autocrlf to true, right? 关于这个问题,您将core.autocrlf设置为true,对吗? It's a config to be used when you're on Windows and working on a repo made in Unix. 当您在Windows上并使用Unix中的存储库时,将使用该配置。 So it's not for you. 所以它不适合你。 This config converts CRLF to LF when add, which is probably the cause of the issue. 添加时此配置将CRLF转换为LF,这可能是问题的原因。 You can set core.autocrlf to false by: 您可以通过以下方式将core.autocrlf设置为false:

git config --local core.autocrlf false

Also run it with --global instead of --local if you want the config globally. 另外随着运行--global而不是--local如果你想在全球的配置。

There appear to be a couple of issues now that the question is updated. 现在,问题已更新,似乎有几个问题。

Different OSs use different line endings. 不同的操作系统使用不同的行尾。

Git can be configured to leave them alone so it doesn't try to change them every time. 可以将Git配置为不理会它们,因此它不会尝试每次更改它们。 More on that in this question and answer: How to change line-ending settings 有关此问题和答案的更多信息: 如何更改行尾设置

The other issue is potentially that the files in question are untracked and therefore aren't being stashed for that reason. 另一个问题是有问题的文件可能未被跟踪,因此不会因为这个原因被隐藏。

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

Then 然后

git stash

Then you will be able to git pull . 然后,您将可以git pull

The output from git status will always explain what's going on. git status的输出将始终说明发生了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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