Git:分佈式版本控制軟件
安裝Git
1、GIT下載
2、安裝時: 只需要修改Use git from git bash only…,其他默認下一步
3、配置path: E:\programs\Git\bin
4、配置git:用戶名和郵箱
右鍵-git bash
git config --global user.name "xx"
git config --global user.email "[email protected]"
5、爲了 在本地 和遠程倉庫之間進行 免密鑰登錄,可以配置ssh
①先本地生成ssh:
ssh-keygen -t rsa -C [email protected] //一直回車
②發送給遠程:
github - settings - SSH and … - New SSH - title任意、key中輸入 剛纔在本地生成的ssh:
將本地剛纔生成的id_rsa.pub(一般在C:\Users\用戶名.ssh)內容複製到遠程的Key中
③:測試連通性:
ssh -T [email protected]
如果本地和遠程成功通信,則可以在 /.ssh目錄中 發現known_hosts文件
常用命令
git add:將本地文件 增加到暫存區
git commit:將暫存區的內容 提交到 本地倉庫(本地分支,默認master分支)
git push:將本地倉庫的內容 推送到 遠程倉庫(遠程分支)
git pull:將遠程倉庫(遠程分支)的內容 拉取到 本地倉庫(本地分支)
示例
1、在本地新建git項目
在項目根目錄 右鍵 - git bash - git init
2、 在遠程建立git項目
new-建立項目- 生成 [email protected]:yanqun/mygitremote.git
3、本地項目-遠程項目關聯
git remote add origin [email protected]:yanqun/mygitremote.git
(新建倉庫後獲得的那個鏈接)
4、第一次發佈項目 (本地-遠程)
git add . //文件-暫存區
git commit -m "註釋內容" //暫存區-本地分支(默認master)
git push -u origin master
5、第一次下載項目(遠程-本地)
git clone [email protected]:yanqun/mygitremote.git(點擊GItHub的
clone會有鏈接)
6、後續提交(本地-遠程)
(在當前工作目錄 右鍵-git bash)
git add.
git commit -m "提交到分支"
git push origin master
7、更新(遠程-本地)
git pull
Egit
在Eclipse中操作git
目前的eclipse基本都支持git,如果不支持 則到eclplise marktplace 搜git安裝
配置:
a.team-git-configuration -郵箱 用戶名
b.general -network -ssh2選中 生成的ssh目錄
第一次發佈
share project
加入暫存區add to index
提交到本地分支commit
將項目推送到遠程 右鍵-team -remote -push —
後續提交
team-add to index
team -commit
team -push
commit時:
commit and push 或commit按鈕的區別:
commit按鈕:不能單獨的Push某一個文件,只能Push整個項目
commit and push:可以 單獨Push某一個文件
第一次下載
import -clone -輸入 https/ssh的唯一標示符
更新
team - remote -pull
git衝突的解決:
發現衝突: 進入同步視圖 右鍵——team - synchronized…
解決:
添加到本地暫存區 add to index
提交到本地分支 commit
更新服務端的分支內容 到本地分支 pull
修改衝突:直接修改 或者 merge tool
(—>已經變爲了普通本地文件)
add to index
commit push
git多個人 團隊協作開發
github中 該項目 -settings
增加合作者: Collaborators 加入 合作者:github 全名或郵箱
發送邀請鏈接
合作伙伴: 打開該鏈接、接受邀請 :合作開發…clone項目、修改、add \commit\push