githug游戏命令记录(持续更新)

Githug is designed to give you a practical way of learning git. It has a series of levels, each requiring you to use git commands to arrive at a correct answer.

Githug 旨在为您提供一种实用的学习 git 的方法。它有一系列级别,每一关都要求您使用 git 命令才能得出正确答案。

使用githug会提示切换目录,使用cd git_hug进入游戏,使用githug验证是否通关。


第一关(Init)

a new directory, ‘git_hug’, has been created; initialize an empty repository in it.

已创建一个新目录“git_hug”;初始化其中的空存储库。

git init

第二关(Config)

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

设置您的 git 名称和电子邮件,这很重要,这样您的提交才能被授权。

git config --user.name "your-username"
git config --user.email "your-email-address"

更多参考git configgit config的全局和本地配置

第三关 (Add)

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.

您的文件夹中有一个名为README的文件,您应该将其添加到您的暂存区域
注意:使用新存储库开始每个级别。不要查找前一个文件。

git add README

第四关 (Commit)

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

'README 文件已添加到您的暂存区域,现在提交它。
(每次 commit 使用 -m 参数加上备注是个好习惯)

git commit -m add "README"

第五关(Clone)

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

在 https://github.com/Gazler/cloneme 克隆存储库。

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

第六关(Clone to folder)

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

在 https://github.com/Gazler/cloneme 到“my_cloned_repo”处克隆存储库

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

下面的第七关-第八关用到了gitignore,相关的知识可以先看一下博客

[1].gitignore的用法
[2]Git中.gitignore的配置(git上传忽略文件/文件夹)

第七关(ignore)

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.

文本编辑器’vim’为当前打开的所有文件创建以.swp结尾的文件(交换文件)。 我们不希望它们爬到版本库中。 让这个版本库忽略那些以.swp结尾的交换文件。

git_hug文件夹下面我们看到有一个.gitignore文件,用你熟悉的编辑器打开。我用记事本打开了。
在这里插入图片描述
添加语句

*.swp

保存并退出。

第八关(include)

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

注意有几个文件的扩展名是’.a’。 我们想让git忽略所有的文件,除了’lib.a’文件。

git_hug文件夹下面我们看到有一个.gitignore文件,用你熟悉的编辑器打开。我用记事本打开了。

在这里插入图片描述
添加语句:

*.a
!lib.a

保存并退出。

第九关(status)

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

在这个资源库中有一些文件,其中一个文件没有被追踪,是哪个文件?

git status

在这里插入图片描述
database.yml没有被追踪。

第十关(number_of_files_committed)

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

这个版本库里有一些文件,有多少文件会被提交?

git status

找到Changes to be committed的数量,为2。

第十一关(rm)

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

第十二关(rm_cached)

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.

一个文件不小心被添加到你的暂存区域,找出哪个文件并将其从暂存区域移除。 注意不要从文件系统中删除该文件,只从git中删除。

git status

在这里插入图片描述

删除该文件。

git rm --cached deleteme.rb

第十三关(stash)

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

你做了一些修改,想以后再做。你应该保存它们,但不要提交它们。

先看一下文件的状态:

git status

在这里插入图片描述
然后输入命令

git stash

在这里插入图片描述

当我们再查看文件的状态时:

git status

在这里插入图片描述

第十四关(rename)

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

我们有一个名为oldfile.txt的文件。我们想把它重命名为`newfile.txt’,并对这一变化进行修改。

git mv oldfile.txt newfile.txt

第十五关(restructure)

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.

你添加了一些文件到你的仓库,但现在意识到你的项目需要重组了。 建立一个名为src的新文件夹,用Git把所有的.html文件移到这个文件夹里。

建立文件夹:

mkdir src

移动文件到文件夹:

git mv about.html src
git mv contact.html src
git mv index.html src

不知道为什么正则表达式不行orz。会报错 在这里插入图片描述
git mv *.html src

第十六关(log)

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

你会被要求提供最近一次提交的哈希值。 你需要调查版本库的日志来了解。

简单:

git log

在这里插入图片描述
提交出现问题:What is the hash of the most recent commit?
输入黄色commit后面一长串的字符串就可以了。

第十七关(tag)

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

我们有一个git repo,我们想用new_tag来标记当前提交。

git tag new_tag

第十八关(push_tags)

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

仓库中有些标签没有被推送到远程仓库中。现在推送它们。
在这里插入图片描述

查看需要push的tag

git tag

在这里插入图片描述

git push origin master --tags tag_to_be_pushed

在这里插入图片描述

第十九关(commit_amend)

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.

README文件已经提交了,但看起来提交时缺少forgotten_file.rb文件。 添加该文件并修改你之前的提交,使其包含在内。

git status

在这里插入图片描述

git add forgotten_file.rb
git commit --amend

写点修改的东西
在这里插入图片描述

第二十关(commit_in_future)

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

用未来的日期(如明天)提交你的修改。

git commit --date=2023-02-13T10:11:11

注意改明天的日期,我这里使用的日期的格式是ISO格式
在这里插入图片描述

第二十一关(reset)

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).

有两个文件需要提交。 我们的目标是将每个文件都作为单独的提交文件添加,但却意外地添加了两个文件。 使用重置命令(不要提交任何内容)取消文件 to_commit_second.rb 的提交。

git reset to_commit_second.rb

第二十二关(reset_soft)

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

你提交得太快了。现在你想撤销最后一次提交,同时保留索引。

看一下日志:

git log

在这里插入图片描述
复制第二个的版本号回退

git reset --soft d48228d689f3ddf2bdb6c1ca0fe552cfb53bb037

网上也有用

git reset --soft HEAD~1 

在提交代码的时候,commit之后,然后我又在工作区添加了东西,这时候突然发现,上一次的commit有错误的文件,需要重新修改,但是我添加的东西友不想丢失,而且我想修改上一次的提交,这时候可进行git reset --soft 版本号就只是回退提交记录。

第二十三关(checkout_file)

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

文件已修改,但不想保留修改内容。查看上次提交的 config.rb 文件

git checkout config.rb

在这里插入图片描述

第二十四关(remote)

This project has a remote repository.Identify it.

该项目有一个远程存储库,请识别它。

git remote -v

在这里插入图片描述
远程仓库是my_remote_repo。
在这里插入图片描述

第二十五关(remote_url)

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

远程版本库有一个相关的网址。请输入远程位置的网址。

git remote -v

在这里插入图片描述

提交把上面所有的url输入即可,用空格分开通关~
在这里插入图片描述

第二十六关(pull)

You need to pull changes from your origin repository.

您需要从源代码库中提取更改。

查看远程分支:

git branch -a

在这里插入图片描述

git pull origin master

第二十七关(remote_add)

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

添加名为 origin 的远程版本库,网址为 https://github.com/githug/githug

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

第二十八关(push)

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

你的本地主分支与远程 origin/master 分支发生了偏离,请将您的提交重置到 origin/master 分支,然后推送到远程分支。

git pull --rebase origin master
git push origin master

第二十九关(diff)

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

自上次提交后,app.rb 文件已被修改,请找出哪一行发生了变化。

git diff app.rb

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

第三十关(blame)

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

有人在 config.rb 文件中设置了密码,请找出是谁。

在这里插入图片描述
从中可以看出设置密码的人是Spider Man.
在这里插入图片描述

第三十一关(branch)

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

你想处理一段有可能导致崩溃的代码,请创建分支test_code。

git branch test_code

第三十二关(checkout)

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

创建并切换到名为 my_branch 的新分支。 你需要像上一关那样创建一个分支。

git checkout -b my_branch

第三十三关(checkout_tag)

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

您需要修复应用程序 1.2 版本中的一个错误。查看标签 v1.2

git checkout v1.2

第三十四关(checkout_tag_over_branch)

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).

您需要修复应用程序 1.2 版本中的一个错误。查看标签 v1.2(注:还有一个名为 v1.2 的分支)。

git checkout tags/v1.2

第三十五关(branch_at)

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.

你忘了在上一次提交时创建分支,并在其上进行了一次提交。在最后一次提交之前的提交创建分支 test_branch。

先查看已有提交记录:

git log

在这里插入图片描述

git branch命令后加入倒数第二次提交的编号:

git branch test_branch cf9515034ecd3042d152c92d73ece9c39643c7cd

第三十六关(delete_branch)

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

您为项目创建了太多分支。在你的软件仓库中有一个名为 "delete_me "的旧分支,你应该删除它。

git branch -d delete_me

第三十七关(push_branch)

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

您对本地分支做了一些修改,并想共享它,但还没准备好与 "主 "分支合并。 只将 "test_branch "推送到远程仓库

git push origin test_branch

第三十八关(merge)

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

我们在分支 "feature "中有一个文件;让我们把它合并到主分支。

git merge feature

关于git merge可以参考:使用分支——Git Merge命令

第三十九关(fetch)

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

看起来有一个新分支被推送到了我们的远程版本库。在不与本地版本库合并的情况下获取更改

git fetch origin

关于git fetchgit pull的用法可以参见:详解git pull和git fetch的区别:

以及Git:远程分支----git fetch命令的使用

第四十关(rebase)

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.

我们正在使用 git rebase 工作流程,特性分支已经准备好进入主分支。让我们把特性分支重植到主分支上。

关于rebase命令可以查看:git rebase详解(图解+最简单示例,一次就懂)

git log --graph --all

在这里插入图片描述

git rebase master feature
git log --graph --all

可以看到分支重植到主分支上。

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值