722

これが、安定しているはずのブランチで行ったことです...

% git rebase master
First, rewinding head to replay your work on top of it...
Fast-forwarded alpha-0.3.0 to master.
% git status
# On branch alpha-0.3.0
# Your branch is ahead of 'origin/alpha-0.3.0' by 53 commits.
#
nothing to commit (working directory clean)
% git push
Fetching remote heads...
  refs/
  refs/heads/
  refs/tags/
  refs/remotes/
'refs/heads/master': up-to-date
updating 'refs/heads/alpha-0.3.0'
  from cc4b63bebb6e6dd04407f8788938244b78c50285
  to   83c9191dea88d146400853af5eb7555f252001b0
    done
'refs/heads/unstable': up-to-date
Updating remote server info

後で気がついたので、それはすべて間違いでした。このプロセス全体を元に戻し、alpha-0.3.0 ブランチを元に戻したいと思います。

私は何をすべきか?

4

15 に答える 15

1143

You need to make sure that no other users of this repository are fetching the incorrect changes or trying to build on top of the commits that you want removed because you are about to rewind history.

Then you need to 'force' push the old reference.

git push -f origin last_known_good_commit:branch_name

or in your case

git push -f origin cc4b63bebb6:alpha-0.3.0

You may have receive.denyNonFastForwards set on the remote repository. If this is the case, then you will get an error which includes the phrase [remote rejected].

In this scenario, you will have to delete and recreate the branch.

git push origin :alpha-0.3.0
git push origin cc4b63bebb6:refs/heads/alpha-0.3.0

If this doesn't work - perhaps because you have receive.denyDeletes set, then you have to have direct access to the repository. In the remote repository, you then have to do something like the following plumbing command.

git update-ref refs/heads/alpha-0.3.0 cc4b63bebb6 83c9191dea8
于 2009-08-13T07:47:35.643 に答える
194

これもできると思います:

git checkout alpha-0.3.0
git reset --hard cc4b63bebb6
git push origin +alpha-0.3.0

これは、リモート リポジトリをいじる必要がないことを除いて、最後の方法と非常によく似ています。

于 2009-11-24T16:48:49.483 に答える
122

git revertここで提案されているいくつかのアプローチよりも危険性が低くなります。

prompt> git revert 35f6af6f77f116ef922e3d75bc80a4a466f92650
[master 71738a9] Revert "Issue #482 - Fixed bug."
 4 files changed, 30 insertions(+), 42 deletions(-)
prompt> git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
prompt>

35f6af6f77f116ef922e3d75bc80a4a466f92650 を自分のコミットに置き換えます。

于 2012-09-03T11:39:14.517 に答える
46

必要な変更を失うことなくそれを行う方法:

git reset cc4b63b 
git stash
git push -f origin alpha-0.3.0
git stash pop

次に、プッシュするファイルを選択できます

于 2011-11-12T00:04:37.577 に答える
37

共有リポジトリで作業している場合、受け入れられた解決策 (@charles bailey から) は非常に危険です。

ベスト プラクティスとして、共有されているリモート リポジトリにプッシュされたすべてのコミットは「不変」であると見なす必要があります。代わりに「git revert」を使用してください: http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#fixing-mistakes

https://git-scm.com/book/be/v2/Git-Basics-Undoing-Things

于 2011-02-24T02:31:21.677 に答える
23

これを行う別の方法:

  1. 別のブランチを作成する
  2. 「git checkout」を使用して、そのブランチの以前のコミットをチェックアウトします
  3. 新しいブランチをプッシュします。
  4. 古いブランチを削除し、削除をプッシュします (使用git push origin --delete <branch_name>)
  5. 新しいブランチの名前を古いブランチに変更します
  6. もう一度押します。
于 2011-07-25T11:24:33.937 に答える