1. 程式人生 > >Git Bash 常用命令整理

Git Bash 常用命令整理

1. 在指定資料夾中,右鍵git bash開啟命令視窗

2.git init 初始化本地倉庫 當前資料夾中會出現.git資料夾表示成功

3.git status 檢視git狀態

4.命名全域性使用者名稱和郵箱地址

    git conifg --global user.name "xxx"  

    git config --global user.email 'xxx'

5.檢視所有設定 git config --list

6.把遠端專案複製到本地資料夾中 git clone https://:xxx/xxx.git  這應該拉的是master分支

7.git branch -a 列出所有分支

8.git checkout -b dev origin/dev,作用是checkout遠端的dev分支,在本地起名為dev分支,並切換到本地的dev分支

或者使用 git pull origin dev  

    $ git checkout -b '' 切換分支 

    $ git pull origin ''  拉伺服器最新程式碼

9.本地檔案修改後 git status 檢視modified檔案

10.git add filePath 新增檔案到本地快取

11.gir commit -m "註釋" filePath

12.q 退出

13.git pull origin 分支名稱    從伺服器更新最新程式碼

14.git push origin 分支名稱  上傳程式碼到伺服器分支

15.分支合併的其它分支:

git status

git add --all

git commit -m '...'

git push origin xx

git status

git checkout xx

git merge xx

git status

git push origin developer

16. git reset --hard origin/developer 放棄本地修改內容。git checkout a.file 可以撤消本地對檔案a的修改,在add之前使用

17. git branch xxxx 本地建立分支xxxx

18. git checkout -b xxxx 切換到新建的分支

19. git branch -d xxxx 刪除本地分支xxxx

    git branch -r  -d  xxxx 刪除遠端分支xxxx

20. git branch -a 列出所有遠端分支

21. git commit -m 'xxx' yy.file 提交單個檔案

其它命令:

如果出現報錯 fatal: Couldn't find remote ref master或者fatal: 'origin' does not appear to be a git repository以及fatal: Could not read from remote repository.

則需要重新輸入$ git remote add origin [email protected]/xxx.git

git log [file name]

合併程式碼:

git merge dev 

git diff  對比修改內容

git diff index.txt