首页 存档 技术 查看内容

GitHug通关攻略

2018-3-30 13:00 |来自: 互联网 400 0

摘要: 这货叫做githug,而不是大家熟悉的github,其主要目的是通过游戏的形式来让我们练习git的使用。 安装githug githug是ruby写的一个应用。所以先要安装ruby,然后输入 gem install githug 然后就可以在你觉得合适的 ...

这货叫做githug,而不是大家熟悉的github,其主要目的是通过游戏的形式来让我们练习git的使用。


安装githug


githug是ruby写的一个应用。所以先要安装ruby,然后输入

gem install githug

然后就可以在你觉得合适的目录输入githug

********************************************************************************
*                                    Githug                                    *
********************************************************************************
No githug directory found, do you wish to create one? [yn]  y

强烈建议把git的编辑器转换为vim

git config --global core.editor "/usr/local/bin/vim"

Level 1

Level: 1
Difficulty: *

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

开始总是简单的,这题是如何新建一个仓库

cd git_hug
git init
githug

Level 2

Level: 2
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

基础题,教你如何提交文件到暂存区

::: sh
git add README
githug

Level 3

Level: 3
Difficulty: *

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


放到暂存区的文件需要commit,才能提交到本地版本库,可以加-m,写上批注

git commit -m "init"githug

Level 4

Level: 4
Difficulty: *

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

设置自己的用户名和邮箱。

#如果想作为全局设置 可以加上 --globalgit config user.name **
git config user.email "**@**.com"githug

Level 5

Level: 5
Difficulty: *

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

获取远程版本库到本地

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

Level 6

Level: 6
Difficulty: *

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

下载版本库的同时改变目录的名字为my_cloned_repo

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

Level 7

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 .swp files.

如果你想忽略某些文件或者目录,可以在工作目录里添加.gitignore文件并编写过滤规则。这里需要忽略所有后缀为swp的文件

vim .gitignore

:::sh .gitignore
*.swp

Level 8

Level: 8
Difficulty: *

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

这题要求我们找出还没有被放进暂存区的文件。首先我们需要使用git status看看文件没有添加,然后githug 答题就可以了。

git status
githug
database.yml

Level 9

Level: 9
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.

工作目录已经把文件删除了,但是暂存区还有记录,现在我们需要把文件在暂存区删除,避免提交到版本库中。

git status #先看看有哪个文件需要执行删除操作git rm deleteme.rb
githug

Level 10

Level: 10
Difficulty: **

A file (deleteme.rb) 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 system, only from git.

有一个文件deleteme.rb已经放到暂存库中,但我们后悔了,想先不提交这个文件,也就是改变其为untracked状态,我们可以这么做

git status # 确定是哪个文件git rm --cache deleteme.rb
git status # 确定其状态githug

Level 11

Level: 11
Difficulty: **

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

想暂存到目前为止作出的修改,但是不想提交到版本库,git提供了一个命令git stash,所有修改会提交到栈中,相关的恢复操作可以查看帮助文档

git stash
githug

Level 12

Level: 12
Difficulty: ***

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

如果想改变文件名字,而且同时令暂存区产生同样的变化,可以这样

git mv oldfile.txt newfile.txt

Level 13

Level: 13
Difficulty: **

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

查看最近提交的7位哈希值

git log
githug
ac91aad #注意每个人不一样

Level 14

Level: 14
Difficulty: **

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

为版本库添加一个tag,通常我们会为发布的版本添加一个tag以作标识。

git tag new_tag
githug

Level 15

Level: 15
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.

有时候,我们在提交代码到版本库后才发现还有一个文件需要修改才能提交,这时候我们不想再增加一条提交记录,想在原来的提交记录里面加上这个文件,我们就可以像下面这样做,但是如果提交到远程版本库就不可能这样做了。

git add forgotten_file.rb
git commit --amend #跳到令一个页面
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

相关分类

返回顶部