Git 常用命令

一.命令

查看幫助
git help
查看本地分支
git branch
查看遠(yuǎn)程和本地分支
git branch -a
創(chuàng)建一個(gè)名為test的分支
git branch test
修改test分支的名字為test1
git branch -m test1
切換到test1分支
git checkout test1
使當(dāng)前分枝與遠(yuǎn)程分支關(guān)聯(lián)
git branch --set-upstream-to origin/master

創(chuàng)建并切換到該分支
git checkout -b test
創(chuàng)建并且切換到該分支并且與遠(yuǎn)程分支關(guān)聯(lián)

Git在Merge時(shí)提示(no branch)數(shù)據(jù)找回
git reflog // 查看操作記錄

垃圾收集命令(pruning garbage collection)
git gc

git merge origin/master
把本地代碼和已取得的遠(yuǎn)程倉(cāng)庫(kù)最新代碼合并

git rm --cached xqshijie.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate

二.操作

0.下載遠(yuǎn)程代碼
git clone ssh://xxx@103.10.86.30:29418/projectName_ios && scp -p -P 29418 xxx@103.10.86.30:hooks/commit-msg projectName_ios/.git/hooks/

1.提交代碼:
git branch // 查看是否在當(dāng)前分支
git status // 查看當(dāng)前分支狀態(tài)
git pull --rebase // 將服務(wù)器最新代碼更新至本地
運(yùn)行項(xiàng)目,如果有沖突,解決沖突,然后:
git add . // 添加至?xí)捍鎱^(qū)
git rebase --continue
如果沒有沖突,直接執(zhí)行下面的命令
git push origin master // 將文件推到服務(wù)器master分支上

放棄后
回滾已經(jīng)commit的內(nèi)容
git log查看需要回滾到那個(gè)版本,復(fù)制commit id
git reset --hard [commit id]
例如:git reset --hard 8cd5a7cbfb86954a09a739e7d57939a9c8229b4a

追加
git status
git add .
git commit --amend // 追加

切換分支: master —>dev
1.查看:
git branch -a

  • master
    remotes/origin/HEAD -> origin/master
    remotes/origin/dev
    remotes/origin/master

2.切換到 dev 分支
git checkout -b dev -t origin/dev

Branch dev set up to track remote branch dev from origin.
Switched to a new branch 'dev'
3.查看是否切換成功
git branch

  • dev
    master
二.問題
Unable to negotiate with XXXX port 29418: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1
fatal: Could not read from remote repository.
Please make sure you have the correct access rights

原因:這是由于升級(jí)到ubuntu-16.04(Ubuntu(烏班圖)是一個(gè)以桌面應(yīng)用為主的Linux操作系統(tǒng))后出現(xiàn)的
解決:修改~/.ssh/config(需要手動(dòng)創(chuàng)建config文檔),加入
<pre><code>
Host *
KexAlgorithms +diffie-hellman-group1-sha1
</code></pre>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 配置 首先是配置帳號(hào)信息ssh -T git@github.com # 登陸 github 修改項(xiàng)目中的個(gè)人信息 ...
    guanguans閱讀 814評(píng)論 0 3
  • 分布式版本管理工具 git屬于分布式 svn集中式 git安裝 git初始化一個(gè)倉(cāng)庫(kù) 其實(shí)就是創(chuàng)建了一個(gè).git隱...
    SnowDragonYY閱讀 1,586評(píng)論 0 0
  • 一、 Git 命令初識(shí) 在正式介紹Git命令之前,先介紹一下Git 的基本命令和操作,對(duì)Git命令有一個(gè)總體的認(rèn)識(shí)...
    子瘋zp閱讀 70,384評(píng)論 1 18
  • Git是一個(gè)很強(qiáng)大的分布式版本控制系統(tǒng)。它不但適用于管理大型開源軟件的源代碼,管理私人的文檔和源代碼也有很多優(yōu)勢(shì)。...
    Mr_不靠譜_先森閱讀 389評(píng)論 0 1
  • 你們好,未曾謀面的讀書人,我是某某某小姐,第一次來到簡(jiǎn)書。
    花小朱閱讀 175評(píng)論 0 0

友情鏈接更多精彩內(nèi)容