git常用命令

创建 repo: git init
添加修改到暂存区:
git add <file>
提交暂存区修改到当前分支:
git commit -m “<log message>"
查看当前状态(分支指向,change信息):
git status
比较工作区文件与最新版本差别:
git diff HEAD — <file>
显示已提交的所有文件列表:
git show --pretty="format:" --name-only <version num>
丢弃工作区修改(即恢复到最近一次add 或 commit 时的状态):
git checkout — <file>
将文件从暂存区撤回:
git reset <file> (git rm -r --cached <file>)
版本恢复或回退:
git reset —hard HEAD^ , git reset —hard <version num>


提交日志: git log —pretty=oneline
命令日志: git reflog


关联当前 repo 到远端仓库:
git remote add <remote> <address>
修改远端的地址:
git remote set-url origin git@github.com:XXXXX/YYYYY.git
将最新commit 推送到远端分支:
git push <remote> <branch>
从远端分支拉取最新commit 并合并到当期分支:
git pull <remote><branch>
从远端仓库克隆:
repo: git clone <address>


创建分支: git branch <branch>
在远端创建分支(即在本地创建好分支后推送到远端):
git push -u <remote> <branch>
查看分支: git branch
删除分支: git branch -d <branch>
创建并切换到分支: git checkout -b <brach>
从远端克隆分支并切换到该分支:
git checkout -b <remote>/<branch>
切换到分支: git checkout <branch>
合并分支到当前分支: git merge <branch>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值