2017-03-10 11 views
0

gitで3回コミットしました。このような。私はこれら三つのコミット スカッシュしたいgit rebaseを行った後で変更がなくなった

asaurab-3.desktop% git lg 
* 931b405 - (HEAD -> saurabh, origin/saurabh) minor fixes (6 minutes ago) <Saurabh Kumar Agarwal> 
* 838d366 - adding upload and download functionality (15 minutes ago) <Saurabh Kumar Agarwal> 
* 0d62348 - first commit (7 days ago) <Saurabh Kumar Agarwal> 
* 4797854 - (origin/mainline, origin/HEAD, mainline) commit (2 weeks ago) <Perforce Administrator> 

ので、私はそれが3つのコミットして、窓を開け

git rebase -i HEAD~3 

をしました。私はsquashに3つのすべてのpickを置き換え、私は、エラーメッセージのすべての私の変化はなくなっている

* 4797854 - (HEAD, origin/mainline, origin/HEAD, mainline) commit (2 weeks ago) <Perforce Administrator> 

Cannot 'squash' without a previous commit 

git lgショーを得た:wq! .

使用してエディタから存在しています。どうすれば元に戻すことができますか?

これはあなたのリベースがまだ完了していないgit status

git status 
interactive rebase in progress; onto 4797854 
No commands done. 
Next commands to do (3 remaining commands): 
    squash 0d62348 first commit 
    squash 838d366 adding upload and download functionality 
    (use "git rebase --edit-todo" to view and edit) 
You are currently editing a commit while rebasing branch 'saurabh' on '4797854'. 
    (use "git commit --amend" to amend the current commit) 
    (use "git rebase --continue" once you are satisfied with your changes) 

答えて

1

質問に対する回答は、gitステータスのみです。私はその後、以前

git rebase --edit-todo 

をした

、私はすべての3つの中でスカッシュをしたので、このエラーが来ていました。私は最初のコミットを選んだ後、他の2つのコミットのためにスカッシュしました。私は自分の変更を保存しました。

その後、私はそれは私の問題を解決し

git rebase --continue 

ました。

1

の出力です。それはエラーではなく、ちょっとした情報が溜まっている間のものです。 rebase --continueを実行してリベースを終了します。

$ git rebase --continue  # repeat the command until rebase complete 

私のすべての変更がなくなっています。どうすれば元に戻すことができますか?

OR、ご希望のコミットにリベースとチェックアウトを中止することができます。 git reflog出力から選択できます。

$ git rebase --abort  # abort/stop the rebase 

$ git reflog    # copy your desired commit hash 
$ git checkout <commit> # I guess here, desired commit = 931b405 

は今、あなたはまた、soft resetで最後の3つのコミットをつぶすことができ

$ git checkout -b new-branch 

新しいブランチを作成します。

$ git reset --soft HEAD~3 
$ git add . 
$ git commit -m 'Squash last three commits' 

$ git push origin HEAD  # push to remote 
+0

恐らく 'git rebase --abort'が理にかなっています。対話型スクリプトが壊れているためにrebaseがエラーになる場合、 '--continue'は大きな違いはありません。 –

+0

はい、明らかに 'git rebase --abort'はリベースを止め、以前の作業ツリーに戻ります。しかし、私はここではエラーではないと思っています。 –

+1

はい@sajibkhan、これは誤りではありません。これは、リベース中の定期的な情報です。私はgit logを見て気にしませんでした。 –

関連する問題