git学习--githug1-20关

来源:互联网 发布:风水峦头自学 知乎 编辑:程序博客网 时间:2024/05/17 23:53

点亮git技能树
项目代码托管用git管理也有一年多了,平常也用的最多的也就是clone,pull,commit,push等等,对git的其他的用法也就是用到的时候google,但是没有一个系统的学习方法,在逛论坛、看帖子的时候偶尔看到一个好玩的,又可以系统的学习git的游戏,名字叫githug,欲知详情,请移步https://github.com/Gazler/githug。为了巩固记忆,在此特地复习一下。安装完成后,在命令行输入githug即可开始游戏,每一关完成后再输入githug,如果命令正确即可进入到下一关,重置当前关卡 githug reset,获取帮助:githug hint。
1、
Name: init
Level: 1
Difficulty: *
A new directory, git_hug, has been created; initialize an empty repository in it.
Answer:git init
2、
Name: config
Level: 2
Difficulty: *
Set up your git name and email, this is important so that your commits can be identified.
Answer:git config –global user.name ‘xxx’
git config –global user.email ‘xx@163.com’
3、
Name: add
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
4、
Name: commit
Level: 4
Difficulty: *
The README file has been added to your staging area, now commit it.
Answer:git commit -m ‘add readme’
5、
Name: clone
Level: 5
Difficulty: *
Clone the repository at https://github.com/Gazler/cloneme.
Answer:git clone https://github.com/Gazler/cloneme
6、
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
7、
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: 在 .gitignore 文件中添加 *.swp 即可忽略所有以.swp结尾的文件
8、
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:编辑.gitignore,添加*.a,!lib.a
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 命令查看哪些文件还没有建立git追踪信息,答案为: database.yml
10、
Name: number_of_files_committed
Level: 10
Difficulty: *
There are some files in this repository, how many of the files will be committed?
Answer:还是利用git status找出哪些文件还没有提交的,答案为:2
11、
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 删除
注:关于rm 和 git rm的区别可以参考:http://blog.csdn.net/jfkidear/article/details/12152167
12、
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 rm –cached deleteme.rb
注:当我们希望删除暂存区或分支上的文件,同时本地也不在需要这个文件了使用git rm file ,当我们只希望删除分支上的文件,但是本地还是要保留这个文件时则使用 git rm –cache file
13、
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
14、
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 oldfile.txt newfile.txt
git rm oldfile.txt
git add newfile.txt
15、
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 add src && git mv *.html src/
16、
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
注:git log 有好多参数可以用,详情可以使用git log –help 或者 https://git-scm.com/book/zh/v1/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2
17、
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 -a new_tag -m ‘new tag comments’
注:git打标签,关卡中的答案用最简单的方式创建,也可以创建签署标签,详细见:https://git-scm.com/book/zh/v1/Git-%E5%9F%BA%E7%A1%80-%E6%89%93%E6%A0%87%E7%AD%BE
18、
Name: push_tags
Level: 18
Difficulty: **
There are tags in the repository that aren’t pushed into remote repository. Push them now.
From /var/folders/g0/yqt0_q553jb9f0r3gyf26qv80000gn/T/d20170110-34247-6aljfj/
* [new branch] master -> origin/master
Answer: git push origin tag_to_be_pushed
注:先通过git tag 找出要推送的tag,然后和推送分支一样
19、
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
注:git修改最后一次提交
20、
Name: commit_in_future
Level: 20
Difficulty: **
Commit your changes with the future date (e.g. tomorrow).
Answer:git commit –date ‘2017-01-11 00:00:00’

0 0
原创粉丝点击