Git命令行常用指令速查

发布时间 2023-12-04 20:17:31作者: Florange
  • Git本地和远端的交互

Command

Usage

git branch -vv

查看本地各分支和它们关联的远端分支

git branch --set-upstream-to=origin/<remote_branch_name>

关联本地指定分支和远端指定分支

git branch --unset-upstream

取消关联

git checkout -b <local_branch_name><block>origin/<remote_branch_name>

拉取远端指定分支代码到本地新分支

git pull

拉取远端指定分支代码到本地关联分支

git push --set-upstream origin<block><local branch name>

推送本地指定分支代码到远端新分支

git push

将本地新增的commit推送到远端

git push -f

强制更新远端内容使与本地相同

https://www.cnblogs.com/huting-front/p/12106578.htm

修改远端分支名称

  • 本地Git的常用指令

Command

Usage

git branch

查看本地的branch列表

git branch -D <branch name>

删除<branch name>,前提是此时不在该branch

git log

展示当前branch的commit history

git reflog

展示所处于过的commit_id历史

git status

查看暂存区状态

git checkout <branch name>

从当前branch切换到<branch name>

git checkout -b <branch name>

将当前branch复制到一个新的branch并命名为<branch name>
git commit 将git add的内容增加到一个新的commit

git commit --amend

将git add的内容增加到当前的最新commit

git add <file name><block><file name>

将modify的file增加到暂存区

git add .

将modify的所有已tracked的file增加到暂存区

git add -- *

将modify中untracked的file也增加到暂存区

git branch -m <old branch name><block><new branch name>

对本地分支重命名

 

  • 本地Git进阶指令

Command Usage

git reset <commit_id>

回退到过去的某个版本

git reset --hard HEAD^

回退到上一个commit并不保留最新commit的任何痕迹

git reset --hard <commit_id>

回退到指定的某个commit

git reset --mix <commit_id>

回退到指定的某个commit并把在它之后的修改都放在暂存区

git rebase -i <commit_id>

进入rebase状态,指定历史某<commit_id>之后的commit都可编辑

git rebase -i HEAD~3

进入rebase状态,最新commit之前的3个commit内可编辑

git rebase --continue

退出rebase状态

git rebase --abort

放弃rebase并退出

git stash

将未commit的修改暂存

git stash pop

将已暂存的修改释放

git clean -f <file><block><file>

清理untracked files

git clean -fd <path><block><path>

 

git cherry-pick <commit_id>

cherry-pick