【问题标题】:Reset to previous commit in a separate directory在单独的目录中重置为先前的提交
【发布时间】:2016-10-17 03:51:24
【问题描述】:

随着我更新 cocoapods,我的项目中的一些文件发生了变化。我使用 bitbucket 来保存我的更改。现在,我想将之前的提交(带有 id)下载到不同的目录,然后复制/粘贴必要的文件。而且我不希望下载影响 git 上的任何内容(直到我复制/粘贴文件)。首先我将git clone 项目放到另一个文件夹中。

现在,我遇到了

git reset --hard & git reset --soft

我真的不知道主要区别是什么。我应该使用哪一个?

【问题讨论】:

    标签: git terminal bitbucket


    【解决方案1】:

    来自man git

        git reset [<mode>] [<commit>]
           This form resets the current branch head to <commit> and possibly updates the index (resetting it to the tree of <commit>) and the working tree depending on <mode>. If <mode> is omitted, defaults to
           "--mixed". The <mode> must be one of the following:
    
           --soft
               Does not touch the index file or the working tree at all (but resets the head to <commit>, just like all modes do). This leaves all your changed files "Changes to be committed", as git status would
               put it.
    
           --mixed
               Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.
    
               If -N is specified, removed paths are marked as intent-to-add (see git-add(1)).
    
           --hard
               Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.
    
           --merge
               Resets the index and updates the files in the working tree that are different between <commit> and HEAD, but keeps those which are different between the index and working tree (i.e. which have
               changes which have not been added). If a file that is different between <commit> and the index has unstaged changes, reset is aborted.
    
               In other words, --merge does something like a git read-tree -u -m <commit>, but carries forward unmerged index entries.
    
           --keep
               Resets index entries and updates files in the working tree that are different between <commit> and HEAD. If a file that is different between <commit> and HEAD has local changes, reset is aborted.
    

    所以区别在于 --hard 会丢弃对 Git 控制下的文件的任何本地更改。另一方面,--soft 仅使符号引用 HEAD 指向更早的提交 id。

    【讨论】:

    • 那么,如果我想在不同的目录中拥有上一次提交的副本,而不影响 git 上的任何内容,我应该使用硬还是软?
    • 嗯,这取决于您对“不影响 ... git”的含义以及您对“提交的副本”的确切含义。如果我理解正确,我猜想进行 --hard 重置,因为整个“复制和不同目录”的故事。但是,我相信您可以使用其他 git 命令更轻松地实现目标,但您必须更清楚地重新表述您的问题。
    猜你喜欢
    • 1970-01-01
    • 2015-05-08
    • 2020-12-12
    • 2011-04-25
    • 1970-01-01
    • 2011-01-08
    • 1970-01-01
    相关资源
    最近更新 更多