提交代碼到GitHub(常見錯誤)

引用

1.建立一個新的repository: 
先在github上建立並寫好相關名字,描述。 
$cd ~/hello-world        //到hello-world目錄 
$git init                     //初始化 
$git add .                   //把全部文件加入到索引(不想把全部文件加入,能夠用gitignore或add 具體文件) 
$git commit               //提交到本地倉庫,而後會填寫更新日誌( -m 「更新日誌」也可) 
$git remote add origin git@github.com:WadeLeng/hello-world.git        //增長到remote 
$git push origin master    //push到github上 
2.更新項目(新加了文件): 
$cd ~/hello-world 
$git add .                  //這樣能夠自動判斷新加了哪些文件,或者手動加入文件名字 
$git commit              //提交到本地倉庫 
$git push origin master    //不是新建立的,不用再add 到remote上了 
3.更新項目(沒新加文件,只有刪除或者修改文件): 
$cd ~/hello-world 
$git commit -a          //記錄刪除或修改了哪些文件 
$git push origin master  //提交到github 
4.忽略一些文件,好比*.o等: 
$cd ~/hello-world 
$vim .gitignore     //把文件類型加入到.gitignore中,保存 
而後就能夠git add . 能自動過濾這種文件 
5.clone代碼到本地: 
$git clone git@github.com:WadeLeng/hello-world.git 
假如本地已經存在了代碼,而倉庫裏有更新,把更改的合併到本地的項目: 
$git fetch origin    //獲取遠程更新 
$git merge origin/master //把更新的內容合併到本地分支 
6.撤銷 
$git reset 
7.刪除 
$git rm  * // 不是用rm 
//------------------------------常見錯誤----------------------------------- 
1.$ git remote add origin git@github.com:WadeLeng/hello-world.git 
錯誤提示:fatal: remote origin already exists. 
解決辦法:$ git remote rm origin 
而後在執行:$ git remote add origin git@github.com:WadeLeng/hello-world.git 就不會報錯誤了 
2. $ git push origin master 
錯誤提示:error:failed to push som refs to 
解決辦法:$ git pull origin master //先把遠程服務器github上面的文件拉先來,再push 上去。 


本人遇到的還有一個錯誤就是,工程傳進github 了但是裏頭缺乏文件, 
解決方法 $git add .    (注意一點  。  )表示添加全部文件, 


若是出現沒法提交的狀況 
如: 
引用

error: failed to push some refs to ... 

試試如下方法來強制提交。 
http://www.cnblogs.com/tjuyyl/archive/2011/08/21/2147695.html  
Java代碼   收藏代碼
  1. git push https://github.com/account/repositeName.git +master  
相關文章
相關標籤/搜索