提交代碼到GitHub

github網址
[url]https://github.com/[/url]

引用一下前輩的表述[url]http://blog.csdn.net/hao1056531028/article/details/7767567[/url]
提交更新時
執行git commit後會自動彈出一個txt文件。
如:


# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: net/zcmusicbox/health/taskmybreak/TakeMyBreakFramePainter.java
# new file: net/zcmusicbox/health/taskmybreak/eyes_protect.jpg
# new file: net/zcmusicbox/health/taskmybreak/mountain.jpg
# new file: net/zcmusicbox/health/taskmybreak/path.jpg
# new file: net/zcmusicbox/health/taskmybreak/river.jpg
# modified: net/zcmusicbox/test/util/http/HttpVisiter.java
# new file: net/zcmusicbox/test/util/linkedList/Chain.java
# new file: net/zcmusicbox/test/util/linkedList/LinkedList.java
# new file: net/zcmusicbox/test/util/stack/ArrayStack.java
# new file: net/zcmusicbox/test/util/stack/Stack.java
# modified: net/zcmusicbox/util/regex/Judger.java
#

只需要將要執行的那一行的#符號去掉,然後保存即可。
最後執行git push origin master命令提交
[quote]
1.創建一個新的repository:
先在github上創建並寫好相關名字,描述。
$cd ~/hello-world //到hello-world目錄
$git init //初始化
$git add . //把所有文件加入到索引(不想把所有文件加入,可以用gitignore或add 具體文件)
$git commit //提交到本地倉庫,然後會填寫更新日誌( -m “更新日誌”也可)
$git remote add origin [email protected]: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 [email protected]:WadeLeng/hello-world.git
假如本地已經存在了代碼,而倉庫裏有更新,把更改的合併到本地的項目:
$git fetch origin //獲取遠程更新
$git merge origin/master //把更新的內容合併到本地分支
6.撤銷
$git reset
7.刪除
$git rm * // 不是用rm
//------------------------------常見錯誤-----------------------------------
1.$ git remote add origin [email protected]:WadeLeng/hello-world.git
錯誤提示:fatal: remote origin already exists.
解決辦法:$ git remote rm origin
然後在執行:$ git remote add origin [email protected]: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 . (注意一點 。 )表示添加所有文件,
[/quote]

如果出現無法提交的情況
如:
[quote]
error: failed to push some refs to ...
[/quote]
試試以下方法來強制提交。
[url]http://www.cnblogs.com/tjuyyl/archive/2011/08/21/2147695.html[/url]

git push https://github.com/account/repositeName.git +master
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章