2017-07-28 67 views
0

你好,我真的有一個奇怪的問題。刪除源文件GitHub合併NetBeams

我對所有這些GitHub的東西都很陌生,所以我嘗試了一些東西。 基本上發生的事情是,我在Netbeams中有一個項目,並想在我的GitHub上發佈它。所以我在Github上創建了存儲庫,並想向它添加文件。

因此,我進入了Netbeams和Initialized Git Repository。 之後,我進入Git-> Commit 然後我試圖推送所有的東西,所以遠程 - >推 不知道什麼可能出錯,我無意識地點擊了所有分支的東西,就像有一些東西 - > master或sometig像那樣,我現在真的不知道。

但事情是,它失敗了。所以我不知何故,做一個拉是個好主意,不知道爲什麼。這也是它出錯的地方。點擊所有的東西,它結束了,有一個窗口問我是否要重新組合/合併。我點擊了Rebase。然後另一個窗口彈出,告訴我關於結帳衝突的一些信息,所以我點擊Revert,突然我的文件都消失了。

我設法重新創建了這個。基本上它發生在我有一個項目時,我從GitHub的空項目中拉出來。有什麼辦法讓我的文件恢復嗎?

編輯:從控制檯輸出

4b83b06 (HEAD -> master, origin/master) [email protected]{0}: pull --no-rebase --progress origin: Fast-forward 
    d47acf2 [email protected]{1}: 
    4b83b06 (HEAD -> master, origin/master) [email protected]{2}: commit: Wa 
    d47acf2 [email protected]{3}: checkout: moving from HEAD to master 
    d47acf2 [email protected]{4}: checkout: moving from master to origin/master 
    d47acf2 [email protected]{5}: rebase finished: returning to refs/heads/master 
    d47acf2 [email protected]{6}: checkout: moving from master to d47acf26594fc3d07b7709ff38a56284267ab993 
    330a8a3 [email protected]{7}: commit (initial): 

Git的居留制:

$ git status 
On branch master 
Your branch is up-to-date with 'origin/master'. 
Changes not staged for commit: 
    (use "git add <file>..." to update what will be committed) 
    (use "git checkout -- <file>..." to discard changes in working directory) 

     modified: nbproject/private/private.xml 

Untracked files: 
    (use "git add <file>..." to include in what will be committed) 

     nbproject/project.properties 

no changes added to commit (use "git add" and/or "git commit -a") 

的chceckout消息:的

$ git checkout 330a8a3 
error: Your local changes to the following files would be overwritten by checkout: 
     nbproject/private/private.xml 
Please commit your changes or stash them before you switch branches. 
error: The following untracked working tree files would be overwritten by checkout: 
     nbproject/project.properties 
Please move or remove them before you switch branches. 
Aborting 
+0

打開一個終端,並鍵入'git reflog'。然後'git checkout'之前的提交散列之前。rebasease。 – merlin2011

+0

是否有可能在Windows上? –

+0

Git運行在Windows上,所以它的所有命令也可以在Windows上運行。我會在Windows上推薦'git-bash'。 – merlin2011

回答

0

爲了讓您的文件備份,他們必須一直一部分在你執行rebase之前的「commit」。 要解決,當你試圖籤是第一次提交你得到的消息:你需要你的藏匿工作樹改變

$ git checkout 330a8a3 
error: Your local changes to the following files would be overwritten by checkout: 
nbproject/private/private.xml 
Please commit your changes or stash them before you switch branches. 
error: The following untracked working tree files would be overwritten by checkout: 
nbproject/project.properties 
Please move or remove them before you switch branches. 
Aborting 

。 git阻止你檢出之前的提交,因爲文件nbproject/private/private.xml已在工作樹中更改,並檢出該提交會丟失最近的更改。您應該運行git stash,這將保存您當前的工作樹文件。然後,您可以再次運行該結帳命令,git checkout 330a8a3應完成而不會出錯。現在你應該能夠看到你的原始文件(至少你所有提交到版本庫的文件)

此時,我會將想要的文件複製到其他地方保存。如果你想保留您在該private.xml文件做了修改,運行以下命令:。 git checkout master git stash apply 這將讓您查看最近一次提交關於master,然後在「負荷」更改以前保存的使用git stash

+0

我愛你!我不得不從那裏刪除一些文件,但它們並不重要,我把它們收回了!非常感謝你做的這些。我所做的就是刪除每個文件,比如private.xml和其他文件,然後執行git chceckout 330a8a3並且它能夠工作! –

+0

感謝您的反饋,將我的答案標記爲解決方案,我很高興您的問題得到解決!我建議你閱讀'stash'命令的文檔,因爲使用'git'時它是絕對重要的。 https://git-scm.com/docs/git-stash – instantepiphany