Git的奇技淫巧

小伙伴们,大家好今天给大家推荐的项目是Git的奇技淫巧,不熟悉Git命令的小伙伴可以学习一下,毕竟工作中经常会用到Git。

什么是Git?

Git是一个 “分布式版本管理工具”,简单的理解版本管理工具:大家在写东西的时候都用过 “回撤” 这个功能,但是回撤只能回撤几步,假如想要找回我三天之前的修改,光用 “回撤” 是找不回来的。而 “版本管理工具” 能记录每次的修改,只要提交到版本仓库,你就可以找到之前任何时刻的状态(文本状态)。

下面的内容就是列举了常用的 Git 命令和一些小技巧,可以通过 “页面内查找” 的方式进行快速查询:Ctrl/Command+f。

开卷必读

如果之前未使用过 Git,可以学习 Git 小白教程入门

  1. 一定要先测试命令的效果后,再用于工作环境中,以防造成不能弥补的后果!到时候别拿着砍刀来找我.

  2. 所有的命令都在git version 2.7.4 (Apple Git-66)下测试通过

  3. 统一概念:

  • 工作区:改动(增删文件和内容)
  • 暂存区:输入命令:git add 改动的文件名,此次改动就放到了 ‘暂存区’
  • 本地仓库(简称:本地):输入命令:git commit 此次修改的描述,此次改动就放到了 ’本地仓库’,每个 commit,我叫它为一个 ‘版本’。
  • 远程仓库(简称:远程):输入命令:git push 远程仓库,此次改动就放到了 ‘远程仓库’(GitHub 等)
  • commit-id:输出命令:git log,最上面那行 commit xxxxxx,后面的字符串就是 commit-id
  1. 如果喜欢这个项目,欢迎 Star、提交 Pr.

目录

展示帮助信息

git help -g

The command output as below:

The common Git guides are:
   attributes          Defining attributes per path
   cli                 Git command-line interface and conventions
   core-tutorial       A Git core tutorial for developers
   cvs-migration       Git for CVS users
   diffcore            Tweaking diff output
   everyday            A useful minimum set of commands for Everyday Git
   glossary            A Git Glossary
   hooks               Hooks used by Git
   ignore              Specifies intentionally untracked files to ignore
   modules             Defining submodule properties
   namespaces          Git namespaces
   repository-layout    Git Repository Layout
   revisions           Specifying revisions and ranges for Git
   tutorial            A tutorial introduction to Git
   tutorial-2          A tutorial introduction to Git: part two
   workflows           An overview of recommended workflows with Git

'git help -a' and 'git help -g' list available subcommands and some concept guides. See 'git help <command>' or 'git help <concept>' to read about a specific subcommand or concept.

回到远程仓库的状态

抛弃本地所有的修改,回到远程仓库的状态。

git fetch --all && git reset --hard origin/master

重设第一个 commit

也就是把所有的改动都重新放回工作区,并清空所有的 commit,这样就可以重新提交第一个 commit 了

git update-ref -d HEAD

查看冲突文件列表

展示工作区的冲突文件列表

git diff --name-only --diff-filter=U

快速切换到上一个分支

git checkout -

列出所有远程分支

-r 参数相当于:remote

git branch -r

git 配置 http 和 socks 代理

git config --global https.proxy 'http://127.0.0.1:8001'   # 适用于 privoxy 将 socks 协议转为 http 协议的 http 端口
git config --global http.proxy 'http://127.0.0.1:8001'
git config --global socks.proxy "127.0.0.1:1080"

git 配置 ssh 代理

$ cat ~/.ssh/config
Host gitlab.com
ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p    
Host github.com
ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p    

一图详解

开源项目:https://github.com/521xueweihan/git-tips

今天的推荐不知道大家喜欢吗?如果你们喜欢话,请在文章底部留言或点赞,以表示对我的支持,你们的留言,点赞,转发关注是我持续更新的动力哦!

关注公众号回复:"1024",免费领取一大波学习资源,先到先得哦!

关注我免费领取学习资料

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值