[摘抄自網(wǎng)絡(luò) ]
1.安裝:yum install git
2.Git 常用命令
(1)git init here -- 創(chuàng)建本地倉庫(repository),將會(huì)在文件夾下創(chuàng)建一個(gè) .git 文件夾,.git 文件夾里存儲(chǔ)了所有的版本信息、標(biāo)記等內(nèi)容
(2)git remote add origin git@github.com:winter1991/helloworld.git -- 把本地倉庫和遠(yuǎn)程倉庫關(guān)聯(lián)起來。如果不執(zhí)行這個(gè)命令的話,每次 push 的時(shí)候都需要指定遠(yuǎn)程服務(wù)器的地址
(3)git add -- 從本地倉庫增刪,結(jié)果將會(huì)保存到本機(jī)的緩存里面
(4)git rm
(5)git commit -m "注釋" -- 提交,把本機(jī)緩存中的內(nèi)容提交到本機(jī)的 HEAD 里面
(6)git push origin master -- 把本地的 commit(提交) push 到遠(yuǎn)程服務(wù)器上, origin 也就是之前 git remote add origin 那個(gè)命令里面的 origin,origin 替代了服務(wù)器倉庫地址:git push git@github.com:winter1991/helloworld.git master
(7)git pull origin master -- 從遠(yuǎn)程服務(wù)器 pull 新的改動(dòng)
(8)git status -- 查看狀態(tài)
(9)git add -A -- 提交全部修改
3. git 配置:
git config --global user.name "xxx" -- 配置用戶名,上傳本地 repository 到服務(wù)器上的時(shí)候,在 Github 上會(huì)顯示這里配置的上傳者信息
git config --global user.email "xxx" -- 配置郵箱
git config --list 查看配置列表
配置 sshkey : 上傳代碼時(shí)使用這個(gè) sshkey 來確認(rèn)是否有上傳權(quán)限
(1)創(chuàng)建本地 ssh : ssh-keygen -t rsa -C "Github 的注冊(cè)郵箱"
(2) 在 Github 中添加這個(gè) sshkey :
復(fù)制 C:Documents and SettingsAdministrator.sshid_rsa.pub 文件中的內(nèi)容;
登錄 Github --> Account Setting --> SSH-KEY --> Add SSH-KEY --> 粘貼id_rsa.pub中的內(nèi)容;
(3) 驗(yàn)證: ssh -T git@github.com
出現(xiàn) Hi xxx! Youve successfully authenticated, but GitHub does not provide shell access. 說明配置成功,可以連接上 Github
4.建立倉庫 repository :
git init here -- 創(chuàng)建本地倉庫
git remote add origin git@github.com:用戶名/倉庫名.git -- 把本地倉庫和遠(yuǎn)程倉庫關(guān)聯(lián)起來, 如果不執(zhí)行這個(gè)命令的話,每次 push 的時(shí)候都需要指定遠(yuǎn)程服務(wù)器的地址
5.從遠(yuǎn)程倉庫中下載新的改動(dòng):
git pull origin master
6提交本地修改到遠(yuǎn)程倉庫中:
git add
git add -A -- 將改動(dòng)添加到本地倉庫中
git rm xxx -- 從本地倉庫中刪除指定文件
git rm -r xxx -- 從本地倉庫中刪除指定文件夾
git commit -m "注釋" -- 把本機(jī)緩存中的內(nèi)容提交到本機(jī)的 HEAD 里面
git push origin master -- 把本地的 commit push 到遠(yuǎn)程倉庫中
6.使用 .gitignore 文件忽略指定的內(nèi)容:
(1) 在本地倉庫根目錄創(chuàng)建 .gitignore 文件。Win7 下不能直接創(chuàng)建,可以創(chuàng)建 ".gitignore." 文件,后面的標(biāo)點(diǎn)自動(dòng)被忽略;
(2) 過濾文件和文件夾: [Tt]emp/ 過濾 Temp emp 文件夾; *.suo 過濾 .suo 文件;
(3) 不過濾文件和文件夾: !*.c