Githug 通关笔记

Githug 是一个关于 Git 的游戏,共有55关,每一关对应 Git 的一项操作。整个游戏可以让你通过实际操作来掌握 Git 。记录下自己的通关命令,以后也可以作为Git的 cheatsheet 。

安装

Githug 依赖 Ruby 环境,所以需要先安装 Ruby 。

sudo apt install ruby
sudo gem install githug

命令

Github 有4个命令。

  • play 开始游戏
  • hint 部分关卡有提示
  • reset 恢复本关卡的初始状态
  • levels 显示所有关卡

攻略

init

git init

config

如果只想给当前仓库设置就使用 local ,全局设置用 global 。

git config --local user.name ouyangsong
git config --local user.email songouyang@live.com

add

添加文件到暂存区。

git add README

commit

将暂存区的修改一次性提交到仓库。

git commit -m"add REMADE"

clone

git clone https://github.com/Gazler/cloneme

clone_to_folder

clone 到指定的文件夹中。

git clone https://github.com/Gazler/cloneme my_cloned_repo

ignore

设置 Git 需要忽略的文件。Github 上有很多对应编程语言的 .gitignore 模板.

*.swp

include

*.a
!lib.a

status

查看仓库的状态。

git status

答案是 database.yml

number_of_files_committed

git status

答案是 2

rm

git status
git rm deleteme.rb

rm_cached

git status
git rm --cached deleteme.rb

stash

将当前的修改都暂时保存起来,适合当你有更紧急的 bug 需要去修复,但是当前工作还未完成。

git stash

其他相关的命令:

# 查看保存了哪些工作区
git stash list
# 恢复工作区,但是不删除 stash 的内容
git stash apply
# 删除 stash 的内容
git stash drop
# 结合恢复和删除的功能
git stash pop

rename

git mv oldfile.txt newfile.txt

restructure

mkdir src
git mv *.html src/

log

git log

tag

git tag new_tag

其他相关的命令:

# 查看当前的 tag
git tag
# 给 tag 添加备注信息
git tag -a v0.1.2 -m “0.1.2版本”

push_tags

git tag
git push --tags origin master

其他相关的命令:

# 推送某个 tag
git push origin v1.1

commit_amend

将本次修改附加到上次的 commit 中。

git add forgotten_file.rb
git commit --amend

commit_in_future

# 首先获取当前的时间
date -R
# 输出当前时间:Wed, 22 Nov 2017 17:24:25 +0800
git commit --date "23 Nov 2017 17:22:20 +0800" -m "commit in future"

reset

git reset HEAD to_commit_second.rb
git commit -m"commit to_commit_first.rb"

git reset

  • --soft 参数将上一次的修改放入暂存区
  • --mixed 参数将上一次的修改放入工作区
  • --hard 参数直接将上一次的修改抛弃

reset_soft

git reset --soft HEAD^1

checkout_file

git checkout -- config.rb

remote

git remote

remote_url

git remove -v

答案是 https://github.com/githug/not_a_repo

pull

git pull origin master

remote_add

git remote add origin https://github.com/githug/githug

push

git rebase origin master
git push origin master

diff

git diff

git diff

  • git diff查看工作区与暂存区之间的差异
  • git diff --cached查看暂存区与仓库之间的差异
  • git diff HEAD查看仓库与工作区之间的差异

blame

git blame config.rb

branch

git checkout -b test_code

checkout

git checkout -b my_branch

checkout_tag

git checkout v1.2

checkout_tag_over_branch

# 当分支名和 tag 名字相同时,指定 tags 。
git checkout tags/v1.2

branch_at

# 以上一条 commit 为基础,常见新的 branch 。
git branch test_branch HEAD^1

delete_branch

# -D 强制删除
git branch -d delete_me

push_branch

git push origin test_branch

merge

git merge feature

fetch

git fetch origin

其实git pull就是git fetchgit merge两条命令的功能。

rebase

git rebase master feature

其他相关命令:

git rebase -i HEAD~4

以交互式模式,进入前四条 commit 进行相关操作。

git rebase

rebase_onto

当你发现基于错误的分支进行开发的时候,可以重新 rebase 到正确的分支。

git rebase --onto master wrong_branch readme-update

repack

将版本库未打包的松散对象打包

git repack

cherry-pick

把 feature 分支的某些 commit 合并到 master 。

git cherry-pick ca32a6dac7b6f97975edbe19a4296c2ee7682f68

grep

git grep TODO

rename_commit

git log
git rebase -i dbc4240694ff708af5bc2ba05329b44ef96d747e
# 然后reword第一条commit

squash

git log
git rebase -i af19867dff35833c2ae251a6a86a7ee40b705b14
# 然后将需要合并的 commit 改成 squash 或者简写 s 。

merge_squash

git merge --squash long-feature-branch
git commit -m "long-feature-barnch

reorder

git rebase -i 425164d1310fc664bae9b0c4e4ad7621ebca24f7
# 修改pick的顺序即可

bisect

git bisect start master f608824888b83bbedc1f658be7496ffea467a8fb
git bisect run make test

stage_lines

同一个文件按照行的修改来提交 commit 。

git add -p feature.rb
  • 输入y来缓存该块
  • 输入n不缓存该块
  • 输入e来人工编辑该块
  • 输入d来退出或进入下一个文件
  • 输入s来分割这个块

find_old_branch

git reflog 命令记录了你对仓库的操作。

git reflog
git checkout solve_world_hunger

revert

git revert 1ee8d2cfff0e26c0d7a093e6ffea259b03a8859d

git revert 只会舍弃你选的 commit ,而 git reset 会将你选择的 commit 以及之后的 commit 都舍弃。

restore

git reflog
git checkout 950b31e

conflict

git merge mybranch
vim poem.txt

submodule

git submodule add https://github.com/jackmaney/githug-include-me ./githug-include-me

contribute

在 github 网页端发起 pull request 。

https://www.ouyangsong.com/posts/54288/

转载于:https://www.cnblogs.com/ouyangsong/p/8635079.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值