常用Git命令

2021-06-27 08:45:29 字數 2536 閱讀 4717

下面是我在開發中常用的git命令

1. 配置git

git config --global --add user.email

git config --global --add user.name

2. 建立新的專案

git init

git add

git commit -a -m "***"

git remote add origin 《我的遠端倉庫位址》

git push origin master

3. 從遠端倉庫獲取最新**至本地

git fetch origin master

git log -p master..origin/master

git merge origin/master 或

git pull origin master  

我一般都直接用git pull

4. tag 操作

新增tag

git tag -a -m "comments"

刪除tag

git tag -d

預設git push時,tag是不會上傳的,push時加上--tag可以把tag也上傳

git push origin master --tag

刪除遠端tag:

git push --delete origin

為過去的commit加tag:

有時候我需要為過去的commit加上tag, 首先列出過去的commits:

$ git log --pretty=oneline

d9c9a1e3bb0cf84cdead31be717756ae057a980a configuration classes added

f9154d4690a63c58b8ea91f2b7a0f74a98280c67 remove unused classes, update packetuti

a4d88c3095d514f8a56e4a7d107956cb14debc20 update readme.md

594f89000e3efd1f45685271647338b265c17cd0 create readme.md

697c3445b110f286a5407700dc87c4a135e2fb43 added state machine

97c2be9cc2c686bae310aa898b3af766574cc4ed add apache license statement

b5c34f5ac760c023e0d2ac6db8e17ae7a5f26553 asynchronous rpc

7b113920126ae92ff77b727cfacbaf8b56df5a3a server tps count

943da57a8f0e39c82d36a1f5cdff6c734ea8c6f7 merge remote-tracking branch 'origin/fo

b0ac2805818c7c12ac4b16838883f6a3ad4b162d update

db4a09a20aad6898ef5c5313a1408a0cf8013e2f updates

a663d2c4a53a9349eb361d2a75a77d6369bee497 change rpc client to use queue

d46ed50ad0c263dc214fa9c51d18470f6ebd391c blocking hash map updates to resolve a

99bc1bc9d3b4505675577b45e59afd90bba44a88 added blocking hashmap and bounded bloc

然後選擇需要加tag的commit的編碼,用下面命令給它加上tag:

$ git tag -a v1.2 b5c34f5ac760c023e0d2ac6db8e17ae7a5f26553 -m "comments"

5. 分支操作

檢視分支

git branch

git branch -r

建立分支

git checkout -b newbranch

把分支合併到master:

git checkout master

git merge git push origin master

切換當前分支

git checkout branch

重新命名分支:switch_to_mysql -> mysql

git branch -m switch_to_mysql mysql

git push origin --delete switch_to_mysql

git push origin mysql

從分支b中刪除最後乙個commit

git checkout b

git reset --hard head~1

git push origin head --force

獲取某分支最新**到本地倉庫

git fetch origin

git log -p 

origin/

常用Git命令

附上一些git的常見命令 gitremote add origin git github.com myaccount myproject.git git push u origin master gitinit 建立repository git 命令 help 檢視幫助命令 touchfilenam...

常用Git命令

建立管理倉庫 git initadd和commit git add readme.txt git commit m wrote a readme file 簡略版log git log pretty oneline abbrev commit當前狀態 git status撤銷更改 git check...

常用git命令

修改新增至stage bash git add stage進版本 git commit m your message here 差異對比 git diff head 回退本地檔案 git checkout 若有stage撤銷至stage,沒有則撤銷至head 撤銷stage git reset he...