2016-09-15 42 views
0

我做了一個叫1.3從主分支,然後混帳:幫助檢索當地的PyCharm承諾,WebStorm

$ git checkout 1.3 
    $ git branch --set-upstream-to=origin/1.3 
    $ git push -u origin/1.3 

編輯:我做了,如果說有什麼區別的上述3個步驟之前git push -u origin master

但不知何故,我失去了最後一次本地提交,這意味着我甚至無法推送到Bitbucket?

如何檢索最後一次提交?爲什麼它沿着痕跡丟失或消失?

生成ssh-key作爲personalid後。

這是我的〜/ .ssh/config中

Host bitbucket.org 
    IdentityFile ~/.ssh/id_rsa 

#Default GitHub user 
Host github.com 
    HostName github.com 
    PreferredAuthentications publickey 
    IdentityFile ~/.ssh/b 


# Work user account 
Host bitbucket.org 
    HostName bitbucket.org 
    PreferredAuthentications publickey 
    IdentityFile ~/.ssh/workid 

Host bitbucket.org 
    HostName bitbucket.org 
    PreferredAuthentications publickey 
    IdentityFile ~/.ssh/personalid 
+0

這是'git checkout 1.3'或'git checkout -b 1.3'嗎? – forevergenin

+0

嗨forevergenin:git checkout 1.3同上 – niceseb

+0

'git checkout 1.3'不會創建一個新的分支。它只會檢出一個已經創建的分支。在你的情況下,它看起來像已經有一個名爲'1.3'的分支,它已經檢出。如果你想從當前簽出的分支創建一個新的分支,你必須運行'git checkout -b 1.3'。 – forevergenin

回答

1

如果你還記得在提交信息上次提交,那麼你可以很容易地恢復它。如果你不記得上次提交的任何信息,那麼它會變得有點困難,但仍然可行。運行命令git reflog。它會列出所有以前的提交。有點像撤消清單。從此列表中記下您上次提交的git commit id。現在運行git checkout -b new_1.3 last-or-lost-commit-idnew_1.3現在將丟失的提交作爲它的HEAD。

如果您想將這個新分支推送到遠程,然後運行git push origin -u new_1.3

+0

感謝forevergenin,只有git push origin -u new_1.3沒有工作,在PyCharm IDE VCS中工作 - > Git - > Push。 CLI返回:服務器的主機密鑰未緩存在註冊表中。您 不能保證服務器是您認爲它的計算機。 ... 連接。 將密鑰存儲在緩存中? (y/n)y。但只是無限期地掛在那裏...... – niceseb

+0

爲什麼它首先失去了承諾?謝謝 – niceseb

+0

它沒有丟失。如果我的理解是正確的,那麼當您運行'git checkout 1.3'時,您只需將工作副本從'master'切換到'1.3'。 – forevergenin