Githug

Githug

「闯过这54关,点亮你的Git技能树」 https://codingstyle.cn/topics/51
「Githug」 https://github.com/Gazler/githug


安装

环境:CentOS 7 x64

1. Git

# 安装Git
yum install git-core

2. Ruby

# 安装Ruby
yum install ruby
# 更新Gem源
gem sources -a https://ruby.taobao.org/

3. Githug

# 安装Githug
gem install githug
# 验证
githug --help

基本命令

  • play : 检查是否过关
  • hint : 显示过关提示
  • reset : 重启本关
  • reset 关名:重启到指定某关
  • levels : 显示关卡列表

#1 init

# 初始化仓库
git init

#2 config

# 配置
git config --global user.name "name"
git config --global user.email "email@email.com"

#3 add

# 添加代码
git add README

#4 commit

# 提交代码
git commit README -m "README"

#5 clone

# 克隆代码
git clone https://github.ocm/Gazler/cloneme

#6 clone_to_folder

# 克隆代码到指定目录
git clone https://github.ocm/Gazler/cloneme my_cloned_repo

#7 ignore

# 忽略.swp文件
vi .gitignore
# 添加*.swp

#8 include

# 包含特定文件
vi .gitignore
# 添加*.a
# 添加!lib.a

#9 status

# 查看状态
git status

#10 number_of_files_committed

# 查看待提交文件
git status
# 查看"Changes to be committed"中的文件

#11 rm

# 查看状态
git status
# 移除文件
git rm deletemr.rb

#12 rm_cached

# 从staged状态移除文件,不删除本地文件
git rm --cached deleteme.rb

#13 stash

# 隐藏当前未staged的文件
git stash

#14 rename

# 重命名文件,并staged
git mv oldfile.txt newfile.txt

#15 restructure

# 重构:将committed文件更改目录结构,并staged
mkdir src
git mv *.html src

#16 log

# 查看提交记录
git log

#17 tag

# 给当前commit添加tag
git tag new_tag

#18 push_tags

# 提交tag
git push --tags

#19 commit_amend

# 修正上次commit(未推送)
git add forgotten_file.rb
git commit --amend
# 添加注释信息

#20 commit_in_future

# 指定提交时间,time为具体时间戳或“yyyy-mm-dd hh:MM:ss”
git commit --date 【time】

#21 reset

# 撤销已add的文件
git reset HEAD to_commit_second.rb

#22 reset_soft

# 撤销最后一次commit
git reset --soft HEAD^

#23 checkout_file

# 撤销文件的修改
git checkout config.rb

#24 remote

# 查看远端仓库名,亦可在.git目录下查看conf文件
git remote

#25 remote_url

# 查看远端仓库的地址
git remote show remote_location

#26 pull

# 拉远端代码
git pull origin master

#27 remote_add

# 添加远程仓库
git remote add orgin https://github.com/githug/githug

#28 push

# 重置
git rebase
# 推送代码
git push

#29 diff

# "@@ -23,7"表示:显示从23行开始的连续7行
git diff

#30 blame

# 查看文件每行的修改者
git blame config.rb

#31 branch

# 新建分支
git branch test_code
# 或者
git checkout -b test_code

#32 checkout

# 新建分支,并切换
git branch my_branch
git checkout my_branch
# 或者
git checkout -b my_branch

#33 checkout_tag

# 切到指定tag
git checkout v1.2

#34 checkout_tag_over_branch

# 切到与branch同名的tag
git checkout tags/v1.2

#35 branch_at

# 基于上一次commit切分支
git branch test_branch HEAD^
# or
git branch test_branch HEAD~

#36 delete_branch

# 删除分支
git branch -d delete_me

#37 push_branch

# 推送分支
git push origin test_branch

#38 merge

# 合并分支
git merge feature

#39 fetch

# 拉取远端仓库的所有更新,但不合并,可通过“git log -p oring/new_branch”查看代码
git fetch origin

#40 rebase

# 重置
git rebase master feature

#41 repack

# 优化仓库打包,并移除冗余
git repack -d

#42 cherry-pick

# 查看分支log
git log new-feature -p README.md
# 将其它分支的commit提交到当前分支,commit的hash值可写前几位
git cherry-pick ca32a

#43 grep

# 过滤含有关键词的文件
git grep "TODO" | wc -l

#44 rename-commit

# 查看log
git log --oneline
# 将有错commit前的pick改为reword,保存,修正信息,再保存
git rebase -i HEAD^2

#45 squash

# 查看log
git log --oneline
# 将要合并分支前的pick改为squash,保存,修正信息,再保存
git rebase -i HEAD~4

#46 merge_squash

# 将其它分支所有commit合并成一个到当前分支
git merge --squash long-feature-branch
git commit -am "merge_squash"

#47 reorder

# 查看log
git log --oneline
# 调整分支顺序(由上至下为时间逆序),保存
git rebase -i HEAD~2

#48 bisect

# 确定二分查找范围
git bisect start HEAD f608824
# 执行测试代码,找到代码出错的commit
git bisect run make test
# 退出bisect会话
git bisect reset

#49 stage_lines

# stage部分修改:删除不需要stage的行,保存
git add -e

#50 find_old_branch

# 查看所有分支提交、切换记录
git reflog
git checkout solve_world_hunger

#51 revert

# 查看要撤销commit的hash
git log --oneline
# 撤销
git revert 5be91df

#52 restore

# 查看分支所有操作记录,找到要恢复的commit
git reflog
# 恢复撤销的commit
git reset --hard 4a449ea

#53 conflict

# 合并mybranch
git merge mybranch
# 查看冲突信息
git status
# 编辑冲突文件,删除Git添加的标识
# 提交
git add poem.txt
git commit -am "fix conflict"

#54 submodule

# 添加子模块
git submodule add https://github.com/jackmaney/githug-include-me ./githug-include-me
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值