Git命令

快捷命令

AliasCommand
gstgit status
gcogit checkout
gcmgit checkout master
gcmsggit commit -m
gdgit diff
gdcagit diff –cached
gpgit push

查看分支

  • 查看本地所有分支

    git branch

  • 查看远程所有分支

    git branch -r

  • 查看本地和远程所有分支

    git branch -a
    // 筛选关键字
    git branch -a | grep **

删除分支

  • 删除本地分支

    git branch -d XXX

  • 使用大写的D 强制删除
    git branch -D XXX

  • 删除远程分支和tag

    法一:
    git push origin – delete XXX

    法二:
    git branch -r -d origin/branch-name
    git push origin :branch-name

  • 推送一个空分支到远程分支,其实就相当于删除远程分支

    git push origin :

  • 重命名本地分支

    git branch -m oldName newName

新建分支

  • 创建分支

    git branch (branchname)

  • 切换分支

    git checkout (branchname)

  • 创建新分支并立即切换到该分支
    (新分支与当前分支相同)

    git checkout -b (branchname)

拉取分支

  • 拉取分支到本地
# 拉远程version分支到当前分支 
# pull = fetch+merge
git pull origin version_branch

# 将远程version分支更新到本地version分支
git fetch origin version_branch
  • 将任何分支合并到当前分支中
git merge (branchname)

提交分支

  • 将该文件添加到缓存

    git add

  • 将缓存区内容添加到仓库中

    git commit

  • 将本地仓库推送到远端仓库

    git push [ origin version_branch ]

基本命令

  • 初始化一个 Git 仓库
git init

# 使用指定目录作为Git仓库
git init newrepo 
  • 现有 Git 仓库中拷贝项目
# 克隆仓库的命令格式
git clone <repo>

# 克隆到指定目录
git clone <repo> <directory> 
参数说明:
    repo:Git 仓库
    directory:本地目录
  • 查看项目的当前状态
# 查看上次提交后是否有修改
# 查看项目的当前状态。[简短输出]
git status [ -s ]
  • 已缓存差别
# 已写入缓存与已修改但尚未写入缓存的改动的区别
git diff 

# 尚未缓存的改动
git diff 

# 查看已缓存的改动
# 已经暂存起来的文件(staged)和上次提交时的快照之间(HEAD)的差异
git diff --cached 

# 下一次commit时会提交到HEAD的内容
git diff staged

# 查看已缓存的与未缓存的所有改动
git diff HEAD 

# 显示摘要而非整个diff
git diff --stat 

# 当前目录和另外一个分支的差别
git diff branch2 
  • 历史提交记录
# 列出历史提交记录
git log 

# 查看历史记录的简洁的版本
git log --oneline 

# 查看历史中什么时候出现了分支、合并
git log --oneline --graph 

# 逆向显示所有日志
git log --reverse --oneline 

example

  • 从V1新建yyw分支
git checkout v1
git checkout -b yyw
git pull origin v1
git push origin yyw
  • 提交分支
# 添加到缓存区
git add .

# 提交到本地仓库
git commit -m "fix"

# 将[branch]推送成 [alias] 远程仓库上的[branch]分支
git push [alias] [branch]
  • 处理冲突
# source tree推送
# 本地与远端同名分支冲突
git pull origin <branchName>
git push 

# git lab 合并
# 远端分支合并冲突
>(souce_branch) git pull origin dest_version 
本地处理冲突
git push origin souce_branch
  • git stash
#添加改动到stash
git stash save -a "messeag"

#恢复改动
恢复最近的一次改动
git stash pop

#查看stash列表
git stash list

#选择你想要pop的stash
运行命令
git stash pop stash@{id}
或者 
git stash apply stash@{id}
即可

#删除stash
git stash drop <stash@{id}>

#清除所有stash
git  stash clear 

#git stash pop 与 git stash apply 的区别

git stash pop stash@{id} 会在执行后将对应的stash id 从stash list里删除,

而git stash apply stash@{id} 则会继续保存stash id

附录

# 将文件从缓存区和你的硬盘中(工作目录)删除
git rm file

# 查看当前配置有哪些远程仓库
git remote          

# 删除远程仓库
git remote rm [别名]
1.检查已有的配置信息
  $ git config --list
2.直接查阅某个环境变量的设定,把特定的名字跟在后面即可
  $ git config user.name
3.取消已缓存的内容
  $ git reset HEAD // 回到此HEAD
4.将条目从缓存区中移除
  $ git rm 
5.回滚提交
  $ git revert HEAD
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值