git使用技巧

git别名:

gitconfigglobalalias.cocheckout git config –global alias.ci commit
gitconfigglobalalias.ststatus git config –global alias.br branch

git lg高级配置

$ git config –global alias.lg “log –graph –pretty=format:’%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset’ –abbrev-commit –date=relative”

修改代码

修改代码之后没有提交,临时切换分支打包或者修改bug,这么处理:
gitstashcommit git stash list 暂存区记录
gitstashapply git stash drop 把最近一条的 stash 记录删除了

标签

列出所有tag
gittagtagcommit git tag [tag]
新建一个tag在指定commit
gittag[tag][commit]tag git show [tag]
提交指定tag
gitpush[remote][tag]tag git push [remote] –tags
新建一个分支,指向某个tag
$ git checkout -b [branch] [tag]

切换分支

列出所有远程分支
gitbranchr git branch -a
新建一个分支,但依然停留在当前分支
gitbranch[branchname] git checkout -b [branch]

查看变化

显示暂存区和工作区的差异
gitdiffcommit git diff –cached [file]
显示工作区与当前分支最新commit之间的差异
gitdiffHEAD git diff [first-branch]…[second-branch]
显示某次提交的元数据和内容变化
$ git show [commit]

远程同步

下载远程仓库的所有变动
gitfetch[remote] git remote -v
显示某个远程仓库的信息
gitremoteshow[remote] git remote add [shortname] [url]
取回远程仓库的变化,并与本地分支合并
gitpull[remote][branch] git push [remote] [branch]
强行推送当前分支到远程仓库,即使有冲突
gitpush[remote]force git push [remote] –all
推送当前某个分支到指定新仓库。如:将branch_a的整个数据(包括提交历史)全部提取出来,并建立一个新的仓库repo_b
$ git remote add origin_repo_b git@server_ip:/path/repo_b.git
git push origin_repo_b branch_a

撤销

恢复暂存区的指定文件到工作区
gitcheckout[file]commit git checkout [commit] [file]
恢复上一个commit的所有文件到工作区
gitcheckout.commit git reset [file]
重置暂存区与工作区,与上一次commit保持一致
gitresethardcommit git reset [commit]
重置当前分支的HEAD为指定commit,同时重置暂存区和工作区,与指定commit一致
$ git reset –hard [commit]

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值