git常用命令总结

http://git-scm.com

命令

命令含义
git init初始化仓库
git status查看状态
git add添加文件
git commit -m ‘commit file’提交file
git log [–graph][–pretty=oneline][–abbrev-commit]查看记录
git reflog命令历史
git reset –hard HEAD^回退到上一个版本
git reset –hard commit_idHEAD到某个版本
git diff [HEAD – ] file对比差异
git checkout – file.m丢弃工作区修改
git reset HEAD file.m清空暂存
git rm file.m删除文件
git remote add origin git@github.com:path/repo.git关联github仓库
git remote -v查看远程仓库信息
git push -u origin master**推送**mster分支到远程仓库
git clone git@github.com:path/repo.git克隆远程仓库
branch
git branch查看当前分支
git branch newBranch创建newBranch分支
get checkout newBranch切换到newBranch分支
git checkout -b newBranch创建并切换到newBranch分支
git merge [–no-ff] [-m ‘message’] newBranchf**合并**newBranch分支到当前分支,–no-ff表示no-fastward, 可以看出曾经做过的合并
git branch -d newBranch删除分支
git branch -D newBranch强制删除分支(未合并分支时,-d无法删除)
git checkout -b newBranch origin/newBranch根据远程仓库的newBranch分支创建newBranch分支
git branch –set-upstream newBranch origin/newBranchnewBranch分支关联远程仓库的分支
pull
git pull更新远程仓库
stach
git stash保存现场
git stash liststash列表
git stash apply [stash@{0}]恢复不删除
git stash drop删除stash
git stash pop
tag
git tag
git tag v1.0 [commit_id] [-m ‘message’]打标签
git show [tag_name]查看标签信息
git -s v1.1 [-m ‘message’] [commit_id]PGP签名
git push origin 1.1推送标签
git push origin –tags推送所有标签
git tag -d v1.1删除标签
git push origin :refs/tags/v1.1(先用上一行删除本地标签)删除远程标签
config
git config –global alias.st status创建别名(用于简写)

常用设置

  • 设置ignore文件
    • 在git仓库主目录中添加.gitignore文件,模版
    • 在本地commit .gitignore文件
  • config文件
    • 当前仓库:.git/config
    • 当前用户:~/.gitconfig
  • 打开颜色

    • git config --global color.ui true
    • 或者设置cofig文件
    [color]
        ui = true
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值