English 中文(简体)
如何获得工作目录内容,因为它是具体承诺的内容。
原标题:How can I get working directory content as it was at specific commit

I have a git repository with some commits in it. I want to reproduce exact state of working directory as it was right after specific commit (Here i suppose that i ve commited all changes that were made).

我尝试使用<代码>git 核对,但该指令没有删除工作名录中的现有档案(在预留之后添加)。

说明我问题的简单例子。 我利用以下指挥系统编制了存放处。

u@u-desktop:/tmp/git$ git init
Initialized empty Git repository in /tmp/git/.git/

u@u-desktop:/tmp/git$ echo  ffff  > first.file
u@u-desktop:/tmp/git$ git add first.file
u@u-desktop:/tmp/git$ git commit -m "Important file was added"
[master (root-commit) fb05f7e] Important file was added
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 first.file

u@u-desktop:/tmp/git$ echo  Second line  >> first.file 
u@u-desktop:/tmp/git$ git commit -m "Important data was added" -a
[master df93d04] Important data was added
 1 files changed, 1 insertions(+), 0 deletions(-)

u@u-desktop:/tmp/git$ echo  ssss  > second.file
u@u-desktop:/tmp/git$ git add second.file
u@u-desktop:/tmp/git$ git commit -m "Second important file was added"
[master b6c106a] Second important file was added
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 second.file

u@u-desktop:/tmp/git$ echo  tttt  > third.file
u@u-desktop:/tmp/git$ git add third.file
u@u-desktop:/tmp/git$ git commit -m "Third important file was added"
[master 33fce06] Third important file was added
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 third.file

现在的名录看着这一点。

u@u-desktop:/tmp/git$ ls
first.file  second.file  third.file

www.un.org/spanish/ga/president 内容如下:

u@u-desktop:/tmp/git$ cat first.file 
ffff
Second line

Now i want restore working directory as it looked right after first commit (fb05f7e)

u@u-desktop:/tmp/git$ git checkout fb05f7e .
u@u-desktop:/tmp/git$ cat first.file 
ffff

second.file and third.file are still in the summary.

u@u-desktop:/tmp/git$ ls
first.file  second.file  third.file
最佳回答

删除<条码>。 选自男子网页:

   git checkout [<branch>], git checkout -b|-B <new_branch> [<start
     point>], git checkout [--detach] [<commit>]
       This form switches branches by updating the index, working tree,
       and HEAD to reflect the specified branch or commit.

       (...)

   git checkout [-p|--patch] [<tree-ish>] [--] <pathspec>...
       When <paths> or --patch are given, git checkout does not switch
       branches. It updates the named paths in the working tree from the
       index file or from a named <tree-ish> (most often a commit).

此外,如果您希望删除索引中查到的not文档,则使用git Clean。 (在男子网页上,有“禁忌”选择,你不得不通过指挥线工作。)

问题回答

赞成:

git checkout fb05f7e

... i.e. without specifying the current directory (.) as the path to checkout. You ll find that second.file and third.file are removed as you expect.

因此,<代码>giteckout有两个截然不同的操作方式,取决于您是否提供了一条途径。 如果您确实提供了一条道路,那么它就只提供了一条路:

......从指数文档中或从一个名叫“树木”的树林中更新点名的树冠; (通常为一种承诺)

(http://git-scm.com/docs/git-checkout” rel=“nofollow”>giteckout 文件。) 这只是更新了其他承诺中实际存在的道路。





相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...

热门标签