Git checkout some files despite the conflict

微信扫一扫,分享到朋友圈

Git checkout some files despite the conflict

I frequently find myself wanting to checkout only certain files in a tree but cant because I have modified them locally and dont want the hassle of trying to figure out merge (I dont want to merge anything – I just want the git version of certain files).

So how can I force a checkout of, for example, “db-backup*” where these files are scattered over a directory structure?

e.g

git-parent
  - dir1
    - db-backup1
  - dir2
    - db-backupA

thanks,

r.

There are a few possible solutions, depending on what you want to do

  • If you want to discard your changes
    , you can use

    git checkout -f ...
  • If you want to save your changes for later, but not worry about them for now, you can stash away your changes
    and then do a checkout:

    git stash
    git checkout ...

    To recover your changes, use git stash pop
    (or git stash apply
    ).

  • If you want to simply view Git version of a file
    (and perhaps save it in temporary file, or under other name), you can use git show
    for that:

    git show 
  • If you want to checkout some directory
    or subset of files in some other place
    , you can either use git archive
    as described in “Examples” section of git-archive homepage:

    git archive --format=tar --prefix=subdir/ HEAD:subdir |
        (cd /var/tmp/ && tar xf -)

    Note that it would use version from HEAD (last commit), not from the index, though usually there would be no difference.

    Another way of achieving that is to use --temp
    option of git checkout-index
    , though this can be considered hackery.

HTH

微信扫一扫,分享到朋友圈

Git checkout some files despite the conflict

又一美国巨头跌落:曾每年赚走5千亿,国内每个人都用过它的产品

上一篇

Read digital numbers in JavaScript (Node.js)?

下一篇

你也可能喜欢

Git checkout some files despite the conflict

长按储存图像,分享给朋友