git command


git command



git global setup

git config --global user.name "user name"
git config --global user.email "user@main.com"

git config --list


create a local new repository

cd existing_folder
git init
git add file (more direcotry or file path) (git add . to add all)
git commint -m "submit log"

create a repository via clone

git clone [git repository url]

modify remote repository url

git remote set-url origin
or
git remote rm origin
git remote add origin

查看分支

查看本地分支情況 git branch -a

只查看遠程倉庫分支情況 git branch -r

重命名分支

本地分支a重命名為b git branch -m a_name b_name

創建分支

創建本地分支 git branch 分支名
切換本地分支 git checkout 分支名

從已有的分支 創建新的分支,並切換到新的分支 git checkout -b 分支名

刪除分支

刪除本地分支 git branch -d 本地分支名
刪除遠程分支 git push origin --delete 遠程分支名

刪除遠程舊分支,並push新分支
git push origin 本地分支名稱:遠程舊分支名 遠程新分支名

拉取遠程分支,並創建本地分支

git fetch origin
git checkout -b 本地分支名 origin/遠端分支名

將本地倉庫代碼提交到遠程倉庫

git push origin current_branch
將當前分支推送到origin主機(在遠程主機新建分支)

git push -u origin haha
將本地的haha分支推送到遠程origin主機(遠程主機沒有haha分支,則新建)

git push -u origin main
加了-u,指定默認主機,以后的push, 可以直接用git push 代替git push origin main

將當前分支推送到origin主機的remote_branch分支,常用
git push -u origin local_branch origin/remote_branch

git push origin 本地分支名:遠端分支名
將本地某個分支提交到遠程某個分支


回退

git checkout modify_file
git checkout .

git reset --hard origin/main
git reset --hard HEAD^
git reset --hard last_commint_id

git reset --mixed last_commint_id then git checkout .

git add撤銷
git status 查看add的文件
git reset HEAD 上一次add 的文件全部撤銷
git reset HEAD file_path 對某個文件進行撤銷

log

git log -2
git log -n
輸出最后提交的n條log

git show commint_id

刪除沒有 git add的文件

git clean -n file/directory 顯示可以刪除的文件
git clean -f file 刪除文件
git clean -fd file/directory 刪除文件和目錄



git 生成補丁

git diff ./ > debug_code.patch
打補丁:
patch -p1 < debug_code.patch



create a new repository

git clone git-repository-url
cd repository
git switch -c master
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master


push an existing folder

cd existing_folder
git init --initial-branch=master
git remote add origin git-repository-url
git add .
git commit -m "Initial commit"
git push -u origin master


push an existing Git repository

cd existing_repo
git remote rm origin
git remote rename origin old-origin
git remote add origin git-repository-url
git push -u origin --all
git push -u origin --tags



git clone repo -b branch --depth=1



learngitbranching

https://learngitbranching.js.org/




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM