1、實(shí)際操作
lihs@lihs-PC MINGW64 /d/Eclipse_workspace/workspace/frontend (frontend_zhxxfw)
$ git push origin frontend_zhxxfw:zhxxfw
輸出結(jié)果:
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 441 bytes | 220.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
? 634d240..b76c2b7? frontend_zhxxfw -> zhxxfw
2锚国、Git官方文檔操作指引
中文版v1:https://git-scm.com/book/zh/v1/Git-基礎(chǔ)-取得項(xiàng)目的-Git-倉庫
中文版v2:https://git-scm.com/book/zh/v2/Git-基礎(chǔ)-遠(yuǎn)程倉庫的使用
3敞恋、常用Git命令合集【轉(zhuǎn)】
1) 遠(yuǎn)程倉庫相關(guān)命令
檢出倉庫:$?git?clone?git://github.com/jquery/jquery.git
查看遠(yuǎn)程倉庫:$?git?remote -v
添加遠(yuǎn)程倉庫:$?git?remote add [name] [url]
刪除遠(yuǎn)程倉庫:$?git?remote rm [name]
修改遠(yuǎn)程倉庫:$?git?remote set-url --push[name][newUrl]
拉取遠(yuǎn)程倉庫:$?git?pull [remoteName] [localBranchName]
推送遠(yuǎn)程倉庫:$?git push?[remoteName] [localBranchName]
2)分支(branch)操作相關(guān)命令
查看本地分支:$?git?branch
查看遠(yuǎn)程分支:$?git?branch -r
創(chuàng)建本地分支:$?git?branch [name] ----注意新分支創(chuàng)建后不會自動切換為當(dāng)前分支
切換分支:$?git?checkout [name]
創(chuàng)建新分支并立即切換到新分支:$?git?checkout -b [name]
刪除分支:$?git?branch -d [name] ---- -d選項(xiàng)只能刪除已經(jīng)參與了合并的分支,對于未有合并的分支是無法刪除的呢燥。如果想強(qiáng)制刪除一個分支,可以使用-D選項(xiàng)
合并分支:$?git?merge [name] ----將名稱為[name]的分支與當(dāng)前分支合并
創(chuàng)建遠(yuǎn)程分支(本地分支push到遠(yuǎn)程):$?git push?origin [name]
刪除遠(yuǎn)程分支:$?git push?origin :heads/[name]
????????我從master分支創(chuàng)建了一個issue5560分支,做了一些修改后俊嗽,使用git push?origin master提交,但是顯示的結(jié)果卻是'Everything up-to-date'铃彰,發(fā)生問題的原因是git push?origin master 在沒有track遠(yuǎn)程分支的本地分支中默認(rèn)提交的master分支绍豁,因?yàn)閙aster分支默認(rèn)指向了origin master 分支,這里要使用git push?origin issue5560:master 就可以把issue5560推送到遠(yuǎn)程的master分支了牙捉。
????????如果想把本地的某個分支test提交到遠(yuǎn)程倉庫竹揍,并作為遠(yuǎn)程倉庫的master分支,或者作為另外一個名叫test的分支邪铲,那么可以這么做芬位。
$?git push?origin test:master???????? // 提交本地test分支作為遠(yuǎn)程的master分支?//好像只寫這一句,遠(yuǎn)程的github就會自動創(chuàng)建一個test分支
$?git push?origin test:test????????????? // 提交本地test分支作為遠(yuǎn)程的test分支
如果想刪除遠(yuǎn)程的分支呢带到?類似于上面昧碉,如果:左邊的分支為空,那么將刪除:右邊的遠(yuǎn)程的分支。
$?git push?origin :test????????????? // 剛提交到遠(yuǎn)程的test將被刪除被饿,但是本地還會保存的四康,不用擔(dān)心
3)版本(tag)操作相關(guān)命令
查看版本:$?git?tag
創(chuàng)建版本:$?git?tag [name]
刪除版本:$?git?tag -d [name]
查看遠(yuǎn)程版本:$?git?tag -r
創(chuàng)建遠(yuǎn)程版本(本地版本push到遠(yuǎn)程):$?git push?origin [name]
刪除遠(yuǎn)程版本:$?git push?origin :refs/tags/[name]
4) 子模塊(submodule)相關(guān)操作命令
添加子模塊:$?git?submodule add [url] [path]
如:$?git?submodule add?git://github.com/soberh/ui-libs.git?src/main/webapp/ui-libs
初始化子模塊:$?git?submodule init ----只在首次檢出倉庫時運(yùn)行一次就行
更新子模塊:$?git?submodule update ----每次更新或切換分支后都需要運(yùn)行一下
刪除子模塊:(分4步走哦)
1)$?git?rm --cached [path]
2) 編輯“.gitmodules”文件,將子模塊的相關(guān)配置節(jié)點(diǎn)刪除掉
3) 編輯“.git/config”文件狭握,將子模塊的相關(guān)配置節(jié)點(diǎn)刪除掉
4) 手動刪除子模塊殘留的目錄
5)忽略一些文件闪金、文件夾不提交
在倉庫根目錄下創(chuàng)建名稱為“.gitignore”的文件,寫入不需要的文件夾名或文件论颅,每個元素占一行即可毕泌,如
target
bin
*.db
6)git操作-刪除文件
日期:2012-05-20?來源: bg090721?
git刪除文件
git rm add2.txt
git commit -m "rm test"
git push web
-----------at server
cd?/var/www/foo.git;sudo git update-server-info
------------檢查刪除效果
cd;rm foo3 -rf;git clone http://[某ip]/foo.git foo3
------------更新已經(jīng)存在的local code
cd;cd foo2
git remote add web [某user]@[某ip]:/var/www/foo.git/
git pull web master