git常用命令

git 添加远程仓库:

git remote add origin url

本地推送到远端分支:

git push u origin/xy_v1.6.0

查看远程仓库库:

git remote

删除远程仓库:

git remote rm origin //origin为仓库名

添加远程仓库:

git remote add origin var //origin为仓库名 var 仓库地址

重新命名分支:

git branch -M branchname

重置當前分支的指針爲指定commit,同時重置暫存區,當工做區不變

git reset [commit]

重置當前分支的 HEAD 爲指定 commit,同時重置暫存區和工做區,與指定 commit 一致

 git reset --hard [commit]

重置當前分支的 HEAD 爲指定 commit,但保持暫存區和工做區不變

 git reset --keep [commit]

撤销上次暂存/撤销到上 n 次暂存:(暂存区内提交会恢复到工作区)

git reset HEAD~
git reset HEAD~N

撤销指定版本并提交:

git revert -n [commit]  / git revert [commit]
git commit -m [message]

检出新分支到本地:

git checkout -b new_branch origin_branch

删除本地分支:

git branch -D local_branch

添加到上次提交过程中:

git commit --amend  # 会通过 core.editor 指定的编辑器进行编辑
git commit --amend -m [message]  # 使用一次新的 commit,替代上一次提交
git commit --amend --no-edit   # 不会进入编辑器,直接进行提交

合并多个 commit 为一个完整 commit(前开后闭):

git rebase -i  [startpoint]  [endpoint]

将某一段 commit 粘贴到另一个分支上:

git rebase   [startpoint]   [endpoint]  --onto  [branchName]

日志显示在一行:

git log --pretty=oneline

git查看分支图:

git log --oneline --graph --decorate --all

还原删除分支(本地)

git reflog 已删除分支id

恢复分支 ddd94a4 名为 reback_remove_branch:

git checkout -b reback_remove_branch ddd94a4

将指定的提交(commit)应用于其他分支:

git cherry-pick <commitHash>

转移 HashA,HashB 两或多个个提交:

git cherry-pick <HashA> <HashB> ...

转移一系列的连续提交:

git cherry-pick A..B / git cherry-pick A^..B (包含A提交)

查看文件差异:

git diff 文件

git stash这个命令可以将当前的工作状态保存到git栈,在需要的时候再恢复:

查看当前stash的所有内容
git stash list

查看堆栈中最新保存的stash和当前⽬录的差异
git stash show

保存当前的工作区与暂存区的状态
git stash
git stash save '注释'

默认恢复git栈中最新的一个
git stash pop

将堆栈中的内容恢复到当前分支下
git stash apply
git stash apply stash@{$num}
**cmd中stash@{$num}需要加引号  git stash apply "stash@{$num}" **
(git stash apply不同于 git stash pop。该命令不会将内容从对堆栈中删除)

从堆栈中移除指定的stash
git stash drop stash@{$num}

移除全部的stash
git stash clear

git 文档

posted @ 2023-03-09 17:35  随波追逐  阅读(29)  评论(0编辑  收藏  举报