2016-11-16 48 views
0

我有一個關於git命令的問題。 我試圖從git存儲取消我的更新。 但我無法做到這一點。無法取消我的更新

我使用以下命令。

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

我仍然在努力...

+0

您正在使用哪種操作系統? – Ivan

+0

上面你做了'git stash',然後再次嘗試'git pull'並得到了相同的結果?儲藏後'git status'會顯示你什麼? – bcmcfc

+0

@lvan \t 我使用mac OS X –

回答

1

爲什麼我不取消我的更新?

git checkout .從索引獲取文件並將其恢復到工作目錄。 你的修改已經上演(即在索引中),所以你需要git checkout HEAD .來丟棄它們。

關於這個問題,你把core.autocrlf設置爲true,對吧? 這是一個配置,當你在Windows上並使用Unix製作的repo時可以使用它。所以這不適合你。 此配置在添加時將CRLF轉換爲LF,這可能是問題的原因。 您可以設置核心。autocrlf成假:

git config --local core.autocrlf false 

還與--global而不是--local運行,如果你想在全球的配置。

+0

謝謝!我會試試看。 –

0

似乎有幾個問題,現在的問題是更新。

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

Git可以配置爲讓它們保持獨立,因此它不會嘗試每次都更改它們。更多關於這個問題和答案:How to change line-ending settings

另一個問題可能是所討論的文件未跟蹤,因此不會因此被隱藏。

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

然後

git stash 

然後你就可以git pull

git狀態的輸出將總是解釋發生了什麼。

+0

不幸的是,同樣的錯誤發生。我會更新我的問題。 –

+0

我的同事使用Windows,但我使用mac.probably它可能是原因。 –

+0

您應該在原始問題中包含所有錯誤輸出。它真的不存在嗎? – bcmcfc