git 基本命令介紹

2021-06-27 01:53:41 字數 1853 閱讀 9176

作給開發者,別人搭建git伺服器之後,你呢就配置個人的客戶端:

git config --global user.name "yourname"

git config --global user.email "***[email protected]"

檢出倉庫:

git clone git: my2.6

檢視遠端倉庫:$ git remote -v

檢視本地分支:git branch

檢視遠端分支:git branch -r

刪除本地分支:git branch -d branch_name

選擇分支:git check out branch_name

建立本地分支:git branch branch_name (注意提交**前一定要建立本地分支)

拉取遠端分支,並合併:git pull origin branch_remote:branch_local

檢視狀態:git status

檢視詳細修改:git diff

新增/刪除檔案:git add/rm filename

提交並新增資訊:git commit -m  "your descriptions"

檢視歷史日記:git  log

本地分支推送:git push origin branch_local:branch_remote

還要介紹下恢復撤銷命令:

git reset –mixed:此為預設方式,不帶任何引數的git reset,即時這種方式,它回退到某個版本,只保留原始碼,回退commit和index資訊   :git reset

git reset –soft:回退到某個版本,只回退了commit的資訊,不會恢復到index file一級。如果還要提交,直接commit即可。比如返回到commit前(含有index資訊,這也是跟-mixed的區別) :git reset --soft head^     

git reset –hard:徹底回退到某個版本,本地的原始碼也會變為上乙個版本的內容。如:git reset --hard head^返回上乙個版本

git revert:還原乙個版本的修改,必須提供乙個具體的git版本號,例如'git revert bbaf6fb5060b4875b18ff9ff637ce118256d6f20',git的版本號都是生成的乙個雜湊值

注:reset是指將當前head的內容重置,不會留任何痕跡。git reset --hard head~3,會將最新的3次提交全部重置,就像沒有提交過一樣。根據--soft --mixed --hard,會對working tree和index和head進行重置。revert是撤銷某次提交,但是這次撤銷也會作為一次提交進行儲存。

至於還有許多的內容沒有說,比如git的配置,git(client-server)環境的搭配,各個命令的詳細用法沒有說,以後會慢慢寫出來給大家分享,也歡迎高手指點。

下面是網上找的別人的,我覺得寫的不錯,所以就複製了一部分 

將 current working directory 記為 工作目錄(1)

將 index file 記為 暫存區(2)

將 git repository 記為 **倉庫(3) 

他們之間的提交層次關係是 (1) -> (2) -> (3)

git add完成的是(1) -> (2)

git commit完成的是(2) -> (3)

git commit -a兩者的直接結合 

從時間上看,可以認為(1)是最新的**,(2)比較舊,(3)更舊

按時間排序就是 (1)

it diff得到的是從(2)到(1)的變化

git diff –cached得到的是從(3)到(2)的變化

git diff head得到的是從(3)到(1)的變化

git 基本命令

man git man git commit man git pull man git merge git config global user.name yourname git config global user.email yourname example.com cd home git m...

Git 基本命令

git config global user.name xx git config global user.email x com 1.建立專案資料夾 mkdir myproject 2.進入專案資料夾 cd myproject 3.初始化專案 git init 4.建立 readme.md tou...

Git 基本命令

說明 以下所有操作命令 均在 git bash 下執行,即命令為linux風格 檔案 以 txt 為例 其中,建立某乙個倉庫,在某一具體路徑下 執行 git init即可 幫助命令 git help 建立 respository git init 刪除 respository rm rf git 建...