美文网首页Git程序员
githug 游戏笔记

githug 游戏笔记

作者: 风花花 | 来源:发表于2016-12-30 12:23 被阅读426次

    输入 y ,创建 git_hug 目录
    No githug directory found, do you wish to create one? [yn] y
    Welcome to Githug!

    level 1

    question

    Name: init
    Level: 1
    Difficulty: *

    A new directory, git_hug, has been created; initialize an empty repository in
    it.

    answer

    $ cd git_hug
    $ git init
    

    相关

    cd (Change Directory),跳转目录、切换路径。
    git init在当前目录新建一个Git代码库

    level 2

    question

    Name: config
    Level: 2
    Difficulty: *

    Set up your git name and email, this is important so that your commits can be id
    entified.

    answer

    $ git config [--global] user.name "[name]"
    $ git config [--global] user.email "[email address]"
    

    相关

    git config git 的设置文件为.gitconfig,他可以在全局配置(加上--global),也可以项目配置。
    另:
    git config --list 显示当前的git配置
    git config -e [--global] 编辑git的配置文件

    level 3

    question

    Level: 3
    Difficulty: *

    There is a file in your folder called README, you should add it to your staging area
    Note: You start each level with a new repo. Don't look for files from the previous one.

    answer

    $ git add .\README
    

    相关

    git add将所有修改过的工作文件提交暂存区
    将所有文件添加到暂存区git add .或者git add -A

    git add .git add -A的区别

    • git add .会监控工作区的状态树,使它会把工作时的所有变化提交到暂存区,包括文件内容修改(modified)以及新文件(new),但不包括被删除的文件。
    • git add -ugit add --update的缩写)仅监控已经被add的文件(即tracked file),他会将被修改的文件提交到暂存区。add -u不会提交新文件(untracked file)。
    • git add -Agit add --all的缩写)是上面两个功能的合集。即包括修改的文件、删除的文件以及新文件。

    level 4

    question

    Name: commit
    Level: 4
    Difficulty: *

    The README file has been added to your staging area, now commit it.

    answer

    $ git commit -m 'message'
    

    相关

    git commit -m [message]提交暂存区到仓库区;还可以提交暂存区的指定文件到仓库区git commit [file1] [file2] ... -m [message]
    同时,必须要写 Commit message(提交说明),否则就不允许提交。
    参考:Git 提交的正确姿势:Commit message 编写指南
    另:

    • git commit -a提交工作区自上次commit之后的变化,直接到仓库区
    • git commit -v提交时显示所有diff信息,-v参数表示可以看commit的差异
    • git commit --amend -m [message]使用一次新的commit,替代上一次提交。如果代码没有任何新变化,则用来改写上一次commit的提交信息
    • git commit --amend [file1] [file2] ...重做上一次commit,并包括指定文件的新变化

    level 5

    question

    Name: clone
    Level: 5
    Difficulty: *

    Clone the repository at https://github.com/Gazler/cloneme.

    answer

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

    相关

    git clone支持多种协议,除了HTTP(s)以外,还支持SSH、Git、本地文件协议等,下面是一些例子。

    $ git clone http[s]://example.com/path/to/repo.git/
    $ git clone ssh://example.com/path/to/repo.git/ 
    $ git clone git://example.com/path/to/repo.git/
    $ git clone /opt/git/project.git 
    $ git clone file:///opt/git/project.git
    $ git clone ftp[s]://example.com/path/to/repo.git/
    $ git clone rsync://example.com/path/to/repo.git/
    

    SSH协议的另一种写法

    $ git clone [user@]example.com:path/to/repo.git/
    

    level 6

    question

    Name: clone_to_folder
    Level: 6
    Difficulty: *

    Clone the repository at https://github.com/Gazler/cloneme to my_cloned_repo.

    answer

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

    相关

    git clone <版本库的网址> <本地目录名> 该命令会在本地主机生成一个目录。如果不指定目录名,则与远程主机的版本库同名。

    level 7

    question

    Name: ignore
    Level: 7
    Difficulty: **

    The text editor 'vim' creates files ending in .swp (swap files) for all files that are currently open. We don't want them creeping into the repository. Make this repository ignore those swap files which are ending in .swp.

    answer

    $ touch .gitignore
    $ echo '*.swp'>>.gitignore
    

    相关

    1. 忽略掉某个文件,需要修改.gitignore文件的方法。可以在你的用户目录下创建 ~/.gitignoreglobal 文件中设置全局。
      需要执行 git config --global core.excludesfile ~/.gitignoreglobal来使得它生效。
      • *.a 忽略所有 .a 结尾的文件
      • !lib.a 但 lib.a 除外
      • /TODO 仅仅忽略项目根目录下的 TODO 文件,但不包括 subdir/TODO
      • build/ 忽略 build/ 目录下的所有文件
      • doo/*.txt 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt
    2. .gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。
      正确的做法是在每个clone下来的仓库中手动设置不要检查特定文件的更改情况。
    • git update-index --assume-unchanged PATH 在PATH处输入要忽略的文件。
    • git update-index --no-assume-unchanged PATH 还原。
    1. 另外 git 还提供了另一种 exclude 的方式来做同样的事情,不同的是 .gitignore 这个文件本身会提交到版本库中去,用来保存的是公共的需要排除的文件。
      .git/info/exclude 这里设置的则是你自己本地需要排除的文件。他不会影响到其他人。也不会提交到版本库中去。

    参考:
    Git 忽略一些文件不加入版本控制

    level 8

    question

    Name: include
    Level: 8
    Difficulty: **

    Notice a few files with the '.a' extension. We want git to ignore all but the 'lib.a' file.

    answer

    $ echo '*.a'>>.gitignore
    $ echo '!lib.a'>>.gitignore
    

    相关

    见上

    level 9

    question

    Name: status
    Level: 9
    Difficulty: *

    There are some files in this repository, one of the files is untracked, which file is it?

    answer

    $ git status
    

    答案为:database.yml

    相关

    git status 显示有变更的文件

    level 10

    question

    Name: number_of_files_committed
    Level: 10
    Difficulty: *

    There are some files in this repository, how many of the files will be committed?

    answer

    答案:2

    相关

    git status命令可以列出当前目录所有还没有被git管理的文件和被git管理且被修改但还未提交(git commit)的文件。

    • 命令中”Changes to be committed“中所列的内容是在Index中的内容,commit之后进入Git Directory。
    • 命令中“Changed but not updated”中所列的内容是在Working Directory中的内容,add之后将进入Index。
    • 命令中“Untracked files”中所列的内容是尚未被Git跟踪的内容,add之后进入Index

    git status简介

    level 11

    question

    Name: rm
    Level: 11
    Difficulty: **

    A file has been removed from the working tree, however the file was not removed from the repository. Find out what this file was and remove it.

    answer

    $ git status
    $ git rm deleteme.rb
    

    相关

    git rm [file1] [file2] ...删除工作区文件,并且将这次删除放入暂存区。
    git rm简介

    level 12

    question

    Name: rm_cached
    Level: 12
    Difficulty: **

    A file has accidentally been added to your staging area, find out which file and remove it from the staging area. NOTE Do not remove the file from the file system, only from git.

    answer

    $ git status
    $ git rm --cached deleteme.rb
    

    相关

    git rm --cached [file] 停止追踪指定文件,但该文件会保留在工作区。

    level 13

    question

    Name: stash
    Level: 13
    Difficulty: **

    You've made some changes and want to work on them later. You should save them, but don't commit them.

    answer

    $ git stash
    

    相关

    git stash 用于保存和恢复工作进度。

    • git stash 保存当前的工作进度。会分别对暂存区和工作区的状态进行保存。
    • git stash list 显示进度列表。
    • git stash pop [--index] [<stash>] 如果不使用任何参数,会恢复最新保存的工作进度,并将恢复的工作进度从存储的工作进度列表中清除。
      如果提供<stash>参数(来自git stash list显示的列表),则从该<stash>中恢复。恢复完毕 也将从进度列表中删除<stash>。选项--index除了恢复工作区的文件外,还尝试恢复暂存区。
    • git stash [save [--patch] [-k|--[no]keep-index] [-q|--quiet] [<message>]] 这是第一条命令的完整版。
      • 使用参数--patch会显示工作区和HEAD的差异,通过对差异文件的编辑决定在进度中最终要保存的工作区的内容,通过编辑差异文件可以在进度中排除无关内容。
      • 使用-k或者--keep-index参数,在保存进度后不会将暂存区重置。默认会将暂存区和工作区强制重置。
    • git stash apply [--index] [<stash>] 除了不删除恢复的进度之外,其余和git stash pop 命令一样。
    • git stash drop [<stash>] 删除一个存储的进度。默认删除最新的进度。
    • git stash clear 删除所有存储的进度。
    • git stash branch <branchname> <stash> 基于进度创建分支。

    Git Stash用法

    level 14

    question

    Name: rename
    Level: 14
    Difficulty: ***

    We have a file called oldfile.txt. We want to rename it to newfile.txt and stage this change.

    answer

    $ git mv oldfile.txt newfile.txt
    

    相关

    git mv 重命名文件

    level 15

    question

    Name: restructure
    Level: 15
    Difficulty: ***

    You added some files to your repository, but now realize that your project needs to be restructured. Make a new folder named src and using Git move all of the .html files into this folder.

    answer

    $ mkdir src
    $ git mv *.html src/
    

    相关

    mkdir(make directory) Mkdir 是一个用来在 Linux 系统下创建目录的命令。此命令属于内建命令。

    • mkdir test1 默认情况下不带任何参数运行mkdir命令会在当前目录下创建目录。
    • mkdir test2[ test22 test222] 创建多个目录。
    • mkdir -p test3/test33 递归创建多个目录。例如创建的目录包含子目录,如果找不到父目录,那么这个参数会首先帮助创建父目录。
    • mkdir -m=r test4 使用-m参数,给生成的新目录设置权限。参考:工作中常用Linux命令:mkdir命令
    • mkdir -v test5 创建目录显示信息。

    参考:
    每天一个linux命令(4):mkdir命令

    level 16

    question

    Name: log
    Level: 16
    Difficulty: **

    You will be asked for the hash of most recent commit. You will need to investigate the logs of the repository for this.

    answer

    $ git log
    

    答案为:34b2fd7(commit后 前7位)

    相关

    git log 显示当前分支的版本历史。

    • git log --stat 显示commit历史,以及每次commit发生变更的文件
    • git log -s [keyword] 搜索提交历史,根据关键词
    • git log -p [file] 显示指定文件相关的每一次diff
    • git log -5 --pretty --oneline 显示过去5次提交
    • git log --follow [file]
      git whatchanged [file] 显示某个文件的版本历史,包括文件改名
    • git log [tag] HEAD --pretty-format:%s 显示某个commit之后的所有变动,每个commit占据一行
    • git log [tag] HEAD --grep feature 显示某个commit之后的所有变动,其“提交说明”必须符合搜索条件

    level 17

    question

    Name: tag
    Level: 17
    Difficulty: **

    We have a git repo and we want to tag the current commit with new_tag.

    answer

    $ git tag new_tag
    

    相关

    • git tag 列出所有的tag,在控制台打印出当前仓库的所有标签
    • git tag [tag] 新建一个tag在当前commit
    • git tag [tag] [commit] 新建一个tag在指定commit
    • git tag d [tag] 删除本地tag

    level 18

    question

    Name: push_tags
    Level: 18
    Difficulty: **

    There are tags in the repository that aren't pushed into remote repository. Push them now.

    answer

    $ git push --tags
    

    相关

    默认 git push 不会罢 tag 标签传送到远端服务器上,只有通过显示命令才能分享标签到远端仓库。

    • git push origin [tagname] push 单个 tag
    • git push [origin] --tags push 所有 tag

    level 19

    question

    Name: commit_amend
    Level: 19
    Difficulty: **

    The README file has been committed, but it looks like the file forgotten_file.rb was missing from the commit. Add the file and amend your previous commit to include it.

    answer

    $ git add forgotten_file.rb
    $ git commit --amend -m 'message'
    

    相关

    git commit --amend 合并缓存区的修改和最近的一次commit, 然后用生成的新的commit替换掉老的. 如果缓存区没有内容, 那么利用amend可以修改上一次commit的描述.
    [译]git commit --amend

    level 20

    question

    Name: commit_in_future
    Level: 20
    Difficulty: **

    Commit your changes with the future date (e.g. tomorrow).

    answer

    $ git commit --date 2016.10.08 -m 'message'
    

    相关

    git commit --date <date> 修改提交时间

    level 21

    question

    Name: reset
    Level: 21
    Difficulty: **

    There are two files to be committed. The goal was to add each file as a separate commit, however both were added by accident. Unstage the file to_commit_second.rb using the reset command (don't commit anything).

    answer

    $ git status
    $ git reset HEAD to_commit_second.rb
    

    相关

    reset 命令移动 HEAD 到当前分支的一个 commit, 这可以用来撤销当前分支的一些 commit

    1. git reset [-q] [commit] [--] <paths> 第一种用法是不会重置引用的,即不会修改master文件。
    2. git reset [--soft | --mixed | --hard | --merge | --keep] [-q] [<commit>]
      第二种用法不使用< paths > 则会重置引用,并且参数不同决定是否覆盖暂存区和工作区:
    • git reset -mixed 此为默认方式,不带任何参数的git reset,会退到某个版本只保留源码,回退commit和index信息,staged snapshot 被更新, working directory 未被更改。
    • git reset -soft 回退到某个版本,只回退了commit信息,staged snapshot 和 working directory 都未被改变 (建议在命令行执行后,再输入 git status 查看状态)
    • git reset -hard 彻底回退到某个版本,本地的源码也会变为上一个版本的内容,即staged snapshot 和 working directory 都将回退

    例子:

    #回退所有内容到上一版本 HEAD^的意思是最近一次的提交
    git reset HEAD^
    #回退a.py这个文件的版本到上一个版本 
    git reset HEAD^ a.py 
    #向前回退到第3个版本 
    git reset –soft HEAD~3 
    #将本地的状态回退到和远程的一样 
    git reset –hard origin/master 
    #回退到某个版本 
    git reset 38679ed 
    #回退到上一次提交的状态,按照某一次的commit完全反向的进行一次commit 
    git revert HEAD  
    

    参考:Git版本恢复命令reset

    level 22

    question

    Name: reset_soft
    Level: 22
    Difficulty: **

    You committed too soon. Now you want to undo the last commit, while keeping the index.

    answer

    $ git reset --soft HEAD^
    

    相关

    见上

    level 23

    question

    Name: checkout_file
    Level: 23
    Difficulty: ***

    A file has been modified, but you don't want to keep the modification. Checkout the config.rb file from the last commit.

    answer

    $ git checkout config.rb
    

    相关

    git checkout 检出。

    1. 创建分支 git branch branchName
    2. 切换分支 git checkout branchName
    3. 上面两个命令可以合成一个命令 git checkout -b branchName

    参考:
    git checkout 命令详解
    Git详解之三 Git分支

    level 24

    question

    Name: remote
    Level: 24
    Difficulty: **

    This project has a remote repository. Identify it.

    answer

    $ git remote -v
    

    答案:my_remote_repo

    相关

    • git remote 不带参数,列出已经存在的远程分支
    • git remote -v --verbose 列出详细信息,在每个名字后面
    • git clone -o jQuery https://github.com/jquery/jquery.git
      git remote 想用其他的主机名 需要用 git clone命令的 -o 选项指定
    • git remote show <主机名> 可以查看主机的详细信息
    • git remote add <主机名> <网址> 添加远程主机
    • git remote rm <主机名> 删除远程主机
    • git remore rename <原主机名> <新主机名> 远程主机的改名

    $ tail .git/config 查看remote信息。

    level 25

    question

    Name: remote_url
    Level: 25
    Difficulty: **

    The remote repositories have a url associated to them. Please enter the url of remote_location.

    answer

    $ git remote -v
    

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

    相关

    见上

    level 26

    question

    Name: pull
    Level: 26
    Difficulty: **

    You need to pull changes from your origin repository.

    answer

    $ git pull origin master
    

    相关

    git push origin master 的意思就是上传本地当前分支代码到master分支。
    参考:
    git pull

    level 27

    question

    Name: remote_add
    Level: 27
    Difficulty: **

    Add a remote repository called origin with the url https://github.com/githug/githug

    answer

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

    相关

    见 level 24

    level 28

    question

    Name: push
    Level: 28
    Difficulty: ***

    Your local master branch has diverged from the remote origin/master branch. Rebase your commit onto origin/master and push it to remote.

    answer

    $ git rebase origin/master
    $ git push origin master
    

    相关

    git rebase用于把一个分支的修改合并到当前分支。

    level 29

    question

    Name: diff
    Level: 29
    Difficulty: **

    There have been modifications to the app.rb file since your last commit. Find out which line has changed.

    answer

    $ git diff app.rb
    

    答案:26

    相关

    git diff app.rb查看文件改动

    level 30

    question

    Name: blame
    Level: 30
    Difficulty: **

    Someone has put a password inside the file config.rb find out who it was.

    answer

    $ git blame config.rb
    

    答案:Spider Man

    相关

    git blame得到整个文件的每一行的详细修改信息:包括SHA串,日期和作者。

    level 31

    question

    Name: branch
    Level: 31
    Difficulty: *

    You want to work on a piece of code that has the potential to break things, create the branch test_code.

    answer

    $ git branch test_code
    

    相关

    见上

    level 32

    question

    Name: checkout
    Level: 32
    Difficulty: **

    Create and switch to a new branch called my_branch. You will need to create a branch like you did in the previous level.

    answer

    $ git checkout -b my_branch
    

    相关

    见上

    level 33

    question

    Name: checkout_tag
    Level: 33
    Difficulty: **

    You need to fix a bug in the version 1.2 of your app. Checkout the tag v1.2.

    answer

    $ git checkout v1.2
    

    相关

    标签可以针对某一时间点的版本做标记,常用于版本发布。

    • 列出标签
      • Git tag 在控制台打印出当前仓库的所有标签
      • git tag -l 'v0.1.*' 搜索符合模式的标签
    • 打标签 git标签分为两种类型:轻量标签和附注标签。轻量标签是指向提交对象的引用,标注标签则是仓库中的一个独立对象。建议使用附注标签。
      • git tag v0.1.2-light创建轻量标签
      • git tag -a v0.1.2 -m "0.1.2版本"创建附注标签
      • git tag -a v0.1.1 9fbc3d0 给指定的commit打标签
    • 切换到标签
      • git checkout [tagname] 查看标签信息
      • git show v0.1.2 查看标签的版本信息
    • 删除标签
      • git tag -d v0.1.2 删除标签
    • 标签发布 git push 不会将标签对象提交到git服务器,我们需要进行显示的操作:
      • git push origin v0.1.2 将标签提交到git服务器
      • git push origin -tags 将本地所有标签一次性提交到git服务器

    参考:
    git命令之git tag 给当前分支打标签
    Git 基础 - 打标签
    Git查看、删除、重命名远程分支和tag

    level 34

    question

    Name: checkout_tag_over_branch
    Level: 34
    Difficulty: **

    You need to fix a bug in the version 1.2 of your app. Checkout the tag v1.2 (Note: There is also a branch named v1.2).

    answer

    $ git checkout tags/v1.2
    

    相关

    git checkout tags/v1.2 当标签和分支名相同时,需要指定标签检出

    level 35

    question

    Name: branch_at
    Level: 35
    Difficulty: ***

    You forgot to branch at the previous commit and made a commit on top of it. Create branch test_branch at the commit before the last.

    answer

    一种方法:

    $ git branch test_branch HEAD^1
    

    第二种方法:

    $ git log
    $ git branch test_branch -v 00740b4
    

    找到第二条的id,输入前7位

    相关

    见上

    level 36

    question

    Name: delete_branch
    Level: 36
    Difficulty: **

    You have created too many branches for your project. There is an old branch in your repo called 'delete_me', you should delete it.

    answer

    $ git branch -d delete_me
    

    相关

    见上

    level 37

    question

    Name: push_branch
    Level: 37
    Difficulty: **

    You've made some changes to a local branch and want to share it, but aren't yet ready to merge it with the 'master' branch. Push only 'test_branch' to the remote repository

    answer

    $ git push origin test_branch
    

    相关

    • git push origin master 上面命令表示,将本地的master分支推送到origin主机的master分支。如果后者不存在,则会被新建。
    • git push origin :master省略本地的分支名,则表示删除指定的远程分支,因为这等同与推送一个空的本地分支到远程分支。等同于:git push origin --delete master
    • git push origin 如果当前分支与远程分支直接存在追踪关系,则本地分支和远程分支都可以省略
    • git push 如果当前分支只有一个追踪分支,那么主机名都可以省略
    • git push -u origin master 如果当前分支和多个主机存在追踪关系,则可以使用 -u 选项指定一个默认主机,这样后面就可以不加任何参数使用 git push
    • git push --all origin 不管是否存在对应的远程分支,将本地的所有分支都推送到远程主机。
    • git push origin --tags git push 不会推送标签(tag),除非使用 -tags 选项

    level 38

    question

    Name: merge
    Level: 38
    Difficulty: **

    We have a file in the branch 'feature'; Let's merge it to the master branch.

    answer

    $ git merge feature
    

    相关

    git merge合并分支

    level 39

    question

    Name: fetch
    Level: 39
    Difficulty: **

    Looks like a new branch was pushed into our remote repository. Get the changes without merging them with the local repository

    answer

    $ git fetch origin
    

    相关

    git fetch origin master 取回origin主机的master分支

    level 40

    question

    Name: rebase
    Level: 40
    Difficulty: **

    We are using a git rebase workflow and the feature branch is ready to go into master. Let's rebase the feature branch onto our master branch.

    answer

    $ git checkout feature
    $ git rebase master
    

    相关

    git rebase 命令主要用在从上游分支获取commit信息,并有机的将当前分支和上游分支进行合并
    git rebase [-i | --interactive] [options] [--onto ] []
    git rebase [-i | --interactive] [options] –onto –root []
    git rebase –continue | –skip | –abort

    level 41

    question

    Name: rebase_onto
    Level: 41
    Difficulty: **

    You have created your branch from wrong_branch and already made some commits, and you realise that you needed to create your branch from master. Rebase your commits onto master branch so that you don't have wrong_branch commits.

    answer

    $ git rebase --onto master wrong_branch
    

    相关

    git rebase --onto A B C A 代表的是你实际想要将切片放到哪个分支,B代表切片开始分支(一定要注意的问题是 B 的开闭问题,这里 rebase --onto 的机制是左开右闭)。
    git rebase --onto A B~1 temp 如果想要保留A和C的历史,就需要先在切片的末尾建立一个分支temp。这就代表把B到c之间的历史移到了A上,并且当前temp分支的历史状态就是窝想要的。
    参考:妙用git rebase --onto指令 - Ricky.K

    level 42

    question

    Name: repack
    Level: 42
    Difficulty: **

    Optimise how your repository is packaged ensuring that redundant packs are removed.

    answer

    $ git repack -d
    

    相关

    git repack [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [-b] [--window=<n>] [--depth=<n>]
    git repack -d 包装后,如果新创建的包使一些现有的包冗余,删除多余的包。同时运行 git prune-packed 去除多余的松散对象文件。

    level 43

    question

    Name: cherry-pick
    Level: 43
    Difficulty: ***

    Your new feature isn't worth the time and you're going to delete it. But it has one commit that fills in README file, and you want this commit to be on the master as well.

    answer

    $ git branch
    $ git log new-feature
    $ git cherry-pick ca32a6da
    

    先查看分支列表,得到分支名,查看分支提交记录,最后合并。

    相关

    Git cherry-pick 可以选择某一个分支中的一个或几个commit来进行操作

    level 44

    question

    Name: grep
    Level: 44
    Difficulty: **

    Your project's deadline approaches, you should evaluate how many TODOs are left in your code

    answer

    $ git grep TODO
    

    可以看到有四条

    相关

    git grep 查找git库里面的某段文字

    • git grep xmmap 查看git里面这个仓库里每个使用 ‘xmmap’ 函数的地方。
    • git grep -n xmmap 显示行号。
    • git grep --name-only xmmap 只显示文件名。
    • git grep -c xmmap 查看每个文件里有多少行匹配内容(line matches)。
    • git grep xmmap v1.5.0 查找git仓库里某个特定版本里的内容,在命令行末尾加上表签名(tag reference)。
    • git grep -e '#define' --and -e SORT_DIRENT 组合搜索条件:查找在仓库的哪些地方定义了‘SORT_DIRENT’。
    • git grep --all-match -e '#define' -e SORT_DIRENT 进行或条件搜索。

    level 45

    question

    Name: rename_commit
    Level: 45
    Difficulty: ***

    Correct the typo in the message of your first (non-root) commit.

    answer

    $ git log master
    $ git rebase -i HEAD~2
    

    查看历史提交记录,看到需要修改的为倒数第二个,进入编辑页面,将需要改动的行的pick改为reword。保存退出后在弹出的第二个窗口里修改拼写错误 commmit 改为 commit

    相关

    见上

    level 46

    question

    Name: squash
    Level: 46
    Difficulty: ****

    You have committed several times but would like all those changes to be one commit.

    answer

    $ git rebase -i HEAD~4
    

    将后三个改为s

    相关

    见上

    level 47

    question

    Name: merge_squash
    Level: 47
    Difficulty: ***

    Merge all commits from the long-feature-branch as a single commit.

    answer

    $ git merge --squash long-feature-branch
    $ git commit -m 'message'
    

    相关

    --squash 选项的含义是:本地文件内容与不使用该选项的合并结果相同,但是不提交、不移动 HEAD ,因此需要一条额外的commit命令。其效果相当于将 another 分支上的多个 commit 合并成一个,放在当前分支上,原来的 commit 历史则没有拿过来。

    level 48

    question

    Name: reorder
    Level: 48
    Difficulty: ****

    You have committed several times but in the wrong order. Please reorder your commits.

    answer

    $ git log
    $ git rebase -i HEAD~2
    

    查看历史记录发现提交顺序错误,将前两行顺序调换。

    相关

    见上

    level 49

    question

    Name: bisect
    Level: 49
    Difficulty: ***

    A bug was introduced somewhere along the way. You know that running ruby prog.rb 5 should output 15. You can also run make test. What are the first 7 chars of the hash of the commit that introduced the bug.

    answer

    $ git log --reverse -p prog.rb
    $ git bisect start master f6088248
    $ git bisect run make test
    

    查看最初一次为正确提交,得到版本号。执行完毕后日志里找到 “is the first bad commit” ,得到 18ed2ac。
    (标记):出错了 得到的结果不为这个。。。

    level49

    相关

    • git bisect start
    • git bisect good fb088248
    • git bisect bad master
    • git bisect run make test
    • git bisect reset 回到之前执行 git bisect start 的状态。

    level 50

    question

    Name: stage_lines
    Level: 50
    Difficulty: ****

    You've made changes within a single file that belong to two different features, but neither of the changes are yet staged. Stage only the changes belonging to the first feature.

    answer

    $ git add -p feature.rb
    

    输入e编辑提交内容,删除第二个。

    相关

    见上

    level 51

    question

    Name: find_old_branch
    Level: 51
    Difficulty: ****

    You have been working on a branch but got distracted by a major issue and forgot the name of it. Switch back to that branch.

    answer

    $ git reflog
    $ git checkout solve_world_hunger
    

    查找到另一个分支,切换到另一个分支。

    相关

    reflog 是 git 用来记录引用变化的一种机制。
    git reflog 命令可以对 git 误操作进行数据恢复。

    level 52

    question

    Name: revert
    Level: 52
    Difficulty: ****

    You have committed several times but want to undo the middle commit.
    All commits have been pushed, so you can't change existing history.

    answer

    $ git log
    $ git revert HEAD^1
    

    相关

    修复提交文件中的错误:

    • git reset --hard HEAD 把工作目录中所有未提交的内容清空。
    • git checkout 恢复一个文件
    • git revert HEAD 撤销一次提交

    level 53

    question

    Name: restore
    Level: 53
    Difficulty: ****

    You decided to delete your latest commit by running git reset --hard HEAD^. (Not a smart thing to do.) You then change your mind, and want that commit back. Restore the deleted commit.

    answer

    $ git reflog
    $ git checkout bdbe33d
    

    查看日志,回覆至对应的版本

    相关

    恢复已修改的文件:

    level 54

    question

    Name: conflict
    Level: 54
    Difficulty: ****

    You need to merge mybranch into the current branch (master). But there may be some incorrect changes in mybranch which may cause conflicts. Solve any merge-conflicts you come across and finish the merge.

    answer

    $ git merge mybranch
    $ vim poem.txt
    $ git add poem.txt
    $ git commit -m 'message'
    

    相关

    处理冲突

    level 55

    question

    Name: submodule
    Level: 55
    Difficulty: **

    You want to include the files from the following repo: https://github.com/jackmaney/githug-include-me into a the folder ./githug-include-me. Do this without manually cloning the repo or copying the files from the repo into this repo.

    answer

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

    相关

    git submodule add 子模块仓库地址 路径
    Git Submodule 使用简介

    level 56

    level56

    最后

    好多还是半懂不懂的状态%>_<%... 嘛 有错请指正:-D

    参考文档

    githug史上最全攻略
    Githug通关全攻略
    「Githug」Git 游戏通关流程

    相关文章

      网友评论

        本文标题:githug 游戏笔记

        本文链接:https://www.haomeiwen.com/subject/fndmvttx.html