Git常用命令 回憶錄

2021-10-04 06:02:34 字數 2074 閱讀 4024

設定使用者名稱

git config --global user.name 「yourname」

設定郵箱

git config --global user.email youremail

檢視配置

git config --list

初始化當前資料夾為乙個倉庫

git init 初始化當前資料夾為乙個倉庫

將乙個檔案新增到暫存區

git add 檔名

將所有檔案新增到暫存區(後邊空格加點)

git add .

把暫存區中的修改提交到倉庫中(建議新增說明文字,否則會進入預設檔案編輯器[vi...])

git commit -m 「提交說明」

檢視當前工作區/暫存區的狀態

git status

檢視倉庫中的提交日誌

git log

新增乙個新的遠端倉庫

git remote add [shortname] [url] #(需要設定ssh,在下方有寫)

轉殖雲倉庫到本地

git clone 雲倉庫的url位址

拉取遠端伺服器origin(shortname)的master分支

git pull origin master

git push 雲倉庫的url位址 master(主分支)

git push -u [shortname] master

git push -f origin master #強制提交,不建議!

檢視當前的遠端倉庫

git remote

git remote -v

刪除遠端倉庫

git remote rm [別名]

git fetch shortname

取消已快取的內容

git reset head 檔名

把檔案從暫存區移除(不會刪除目錄中檔案)

git rm --cached 檔名

從git中移除檔案(沒有提交到暫存區)

git rm 檔名

從git中移除檔案(已經提交到暫存區)

git rm -f 檔名

移動或重新命名乙個檔案

git mv oldfilename newfilename

建立分支

git branch (branchname)

切換分支

git checkout (branchname)

合併分支

git merge

列出分支

git branch

刪除分支

git branch -d (branchname)

遠端倉庫(碼雲)

碼雲ssh:

git bash中輸入 ssh-keygen -t rsa -c 「**@.com」 碼雲註冊時郵箱位址

碼雲主頁設定管理公鑰,輸入公鑰標題

將git bash中生成的公鑰(cat id_rsa.pub檔案中內容)填入,確認

本地確認回執 git bash中輸入 ssh -t [email protected] 輸入yes

備註:快取使用者密碼清除

# 快取輸入的使用者名稱和密碼

git config --global credential.helper wincred

# 清除掉快取在git中的使用者名稱和密碼

git credential-manager uninstall

git常用命令 git 部分高階命令備忘錄

常用命令 轉殖 git clone git gitee.com niunafei1 git learning.git git 建立分支 git checkout b dev git 切換分支 git branch dev git checkout dev git 分支刪除 git branch d ...

常用命令 Git 常用命令大全

安裝教程可參照 廖雪峰老師的安裝教程。git config 在git中,使用git config 命令來配置 git 的配置檔案,git配置級別主要有3類 1 倉庫級別 local 本地 git 倉庫級別配置檔案,作用於當前倉庫。優先順序最高 2 使用者級別 global,全域性配置檔案,作用於所有...

git 常用命令

檢視是否存在檔案需要上傳 git status git add git commit m 建立遠端倉庫 git remote add origin 116.255.146.153 ruby cd work daily project.git 更新git fetch 116.255.146.153 r...