6

壊れたマージがあり、作業ディレクトリの変更を元に戻して、壊れている場所を見つけたいと思っています。修正を追加して最終的にチェックインできるように、インデックスを保持したいと考えています。基本的には、作業ディレクトリを HEAD と同じにする必要がありますが、インデックスを変更する必要はありません。これは基本的に、作業ディレクトリへのインデックスに基づいてリバース パッチを適用します。これは a の反対になるようgit resetです。

gitでこれをどのように行いますか?

4

6 に答える 6

6

インデックスをコミットし、作業ディレクトリをリセットしてから、コミットをリセットできます。

$ git commit -m "blah"
$ git reset --hard
$ git reset --soft HEAD^

編集: 元の質問を誤解しているようです。

インデックスに影響を与えずに作業ツリーを HEAD にリセットするには、次の手順を実行します。

$ git checkout -- .
$ git diff --cached | git apply --reverse

(そして、@Brice は既にこの回答を提供しているようです。)

于 2014-06-16T21:26:10.250 に答える
2

リバース パッチは、インデックスの変更ではなく、既存のコミットに対して生成できます。

  1. インデックスの変更をコミットします [差分ブランチにある可能性があります]。
  2. 実行するgit revert -n <commit>

コミットの作業ディレクトリにリバース パッチが生成されます。

于 2012-10-31T07:25:05.463 に答える
1

試しましたgit checkout <commit>か?

のフラグメントgit help checkout

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.

       If -b is given, a new branch is created as if git-branch(1) were called and then checked out; in this case you can use the --track or --no-track
       options, which will be passed to git branch. As a convenience, --track without -b implies branch creation; see the description of --track below.

       If -B is given, <new_branch> is created if it doesn’t exist; otherwise, it is reset. This is the transactional equivalent of

           $ git branch -f <branch> [<start point>]
           $ git checkout <branch>

       that is to say, the branch is not reset/created unless "git checkout" is successful.
于 2012-10-30T20:18:57.807 に答える
1

Maybe you are looking to git stash. With git stash you are able to make the working directory look just like HEAD and you can do anything else when you are in that state. Once you are done, you can git stash pop and get all of your changes back. You have to make sure you don't change the files that are stashed though, otherwise you'll have merge conflicts to resolve.

于 2012-10-30T20:24:32.443 に答える