在单独的目录中重置为先前的提交

Reset to previous commit in a separate directory

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

现在,我遇到了

git reset --hard & git reset --soft

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

来自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。