Git使用方法

2021-08-28 15:35:02 字數 1996 閱讀 3488

git 是最常用的**管理工具,具體功能也不必細說,下面簡單記錄一下 git 的基本的使用方法。

1. 安裝

git --version
2. 配置(config)
git config --global user.name "talonzhang"

git config --global user.email "***@xx.com"

git config --list

1. 初始化倉庫(init)

進入要建立倉庫的目錄執行:

git init
或者在父級目錄執行:

git init repository
倉庫初始化後會自動建立乙個 .git 隱藏檔案。

2. 在 github 上轉殖專案(clone)

git clone 

git clone yyy // 重新命名為 yyy

1. 檢視倉庫狀態(status)

git status
2. 將所有檔案新增到暫存區(add)
git add .
3. 提交(commit)
git commit -m "描述"
4. 檢視版本記錄(log)
git log

git log -p // 顯示具體更新

git log --oneline // 顯示在一行

git log --all // 顯示所有版本

git log --all --graph // 圖示全部歷史記錄

5. 穿越到指定歷史節點(checkout)
git checkout ******x(版本號)	// 回到指定版本

git checkout - // 回到上一版本

1. modified:已修改

2. staged:已暫存

3. committed:已提交

1. 新增標籤

git tag -a tagname -m "備註"	// 預設新增到最近的版本

git tag -a tagname -m "備註" ******x(版本號)// 新增到指定版本

2. 列出所有標籤
git tag
3. 檢視標籤資訊
git show tagname
4. 回溯到指定標籤
git checkout tagname

預設分支為 master 。

1. 建立分支

git branch branchname
2. 切換分支
git checkout branchname	// 切換至已有分支

git checkout -b branchname // 建立並切換至分支

3. 合併分支(merge)
git merge branchname

1. 建立遠端倉庫

以 github 為例,先登入 github 官網,新建倉庫(new repository)。

2. 在本地新增遠端倉庫

git remote add remotename remoteaddress
3. 列出所有遠端倉庫
git remote

git remote -v // 詳細資訊

4. 上傳**(push)
git push -u remotename branchname
5. 拷貝倉庫**(clone)

倉庫名稱預設為 origin 。

git clone
git pull

Git 使用方法

git 常用命令 git init here 建立本地倉庫 repository 將會在資料夾下建立乙個 git 資料夾,git 資料夾裡儲存了所有的版本資訊 標記等內容 git remote add origin git github.com winter1991 helloworld.git 把...

Git 使用方法

git 常用命令 git init here 建立本地倉庫 repository 將會在資料夾下建立乙個 git 資料夾,git 資料夾裡儲存了所有的版本資訊 標記等內容 git remote add origin git github.com winter1991 helloworld.git 把...

Git使用方法

最近專案用到了git,開始,覺得非常難用,後來,也就習慣了。現在,簡單概括下git的常用操作吧,後續的話我會繼續補充的。1 clone 的檢出,使用git轉殖,可以使用圖形化介面,也可以使用命令。2 pull 使用這個命令,可能用svn的人不太習慣,但可以放心,你選擇單個檔案,或者這個專案來pull...