无法取消我的更新

时间:2016-11-16 11:16:38

标签: git git-stash git-checkout

我对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

我还在努力......

2 个答案:

答案 0 :(得分:1)

  

为什么我没有取消更新?

git checkout .从索引中获取文件并将其还原到工作目录。 您的修改已经暂存(即在索引中),因此您需要git checkout HEAD .放弃它们。

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

git config --local core.autocrlf false

如果您想要全局配置,也可以使用--global而不是--local运行它。

答案 1 :(得分:0)

现在似乎有一些问题已经更新。

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

Git可以配置为不让它们单独使用,因此它不会每次都尝试更改它们。有关此问题和答案的更多信息:How to change line-ending settings

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

from __future__ import print_function
import sys
from itertools import islice

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

@static_vars(counter=0)
def take(n, iterable, reset=False):
    "Return next n items of the iterable as same type"
    if reset: take.counter = 0
    take.counter += n
    bob = islice(iterable, take.counter-n, take.counter)
    if isinstance(iterable, dict): return dict(bob)
    elif isinstance(iterable, list): return list(bob)
    elif isinstance(iterable, tuple): return tuple(bob)
    elif isinstance(iterable, set): return set(bob)
    elif isinstance(iterable, file): return file(bob)
    else: return bob

def delete_message_batch2(cx, queue, messages): #returns a string reflecting level of success rather than throwing an exception or True/False
  """
  Deletes a list of messages from a queue in a single request.
  :param cx: A boto connection object.
  :param queue: The :class:`boto.sqs.queue.Queue` from which the messages will be deleted
  :param messages: List of any object or structure with id and receipt_handle attributes such as :class:`boto.sqs.message.Message` objects.
  """
  listof10s = []
  asSuc, asErr, acS, acE = "","",0,0
  res = []
  it = tuple(enumerate(messages))
  params = {}
  tenmsg = take(10,it,True)
  while len(tenmsg)>0:
    listof10s.append(tenmsg)
    tenmsg = take(10,it)
  while len(listof10s)>0:
    tenmsg = listof10s.pop()
    params.clear()
    for i, msg in tenmsg: #enumerate(tenmsg):
      prefix = 'DeleteMessageBatchRequestEntry'
      numb = (i%10)+1
      p_name = '%s.%i.Id' % (prefix, numb)
      params[p_name] = msg.get('id')
      p_name = '%s.%i.ReceiptHandle' % (prefix, numb)
      params[p_name] = msg.get('receipt_handle')
    try:
      go = cx.get_object('DeleteMessageBatch', params, BatchResults, queue.id, verb='POST')
      (sSuc,cS),(sErr,cE) = tup_result_messages(go)
      if cS:
        asSuc += ","+sSuc
        acS += cS
      if cE:
        asErr += ","+sErr
        acE += cE
    except cx.ResponseError:
      eprint("Error in batch delete for queue {}({})\nParams ({}) list: {} ".format(queue.name, queue.id, len(params), params))
    except:
      eprint("Error of unknown type in batch delete for queue {}({})\nParams ({}) list: {} ".format(queue.name, queue.id, len(params), params))
  return stringify_final_tup(asSuc, asErr, acS, acE, expect=len(messages)) #mdel #res

def stringify_final_tup(sSuc="", sErr="", cS=0, cE=0, expect=0):
  if sSuc == "": sSuc="None"
  if sErr == "": sErr="None"
  if cS == expect: sSuc="All"
  if cE == expect: sErr="All"
  return "Up to {} messages removed [{}]\t\tMessages remaining ({}) [{}]".format(cS,sSuc,cE,sErr)

然后

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

然后您就可以git stash

git status的输出将始终解释正在进行的操作。