Wargames与bash知识21

Wargames与bash知识21

Bandit30

在git官网下载一个《pro git》第二版,学习了一下,稍微对git有了认识:

获取git仓库的方法:

1、对现有的项目进行管理,进入该项目目录

git init 初始化仓库

git add 增加追踪文件

git commit 提交

git commit -m "提交信息"

git commit -a 跳过暂存直接提交

克隆仓库

git clone

查看文件状态

git status

查看暂存前后文件变化

git diff

从仓库删除文件

git rm

重命名文件

git mv

查看历史

git log

查看每次提交内容差异

git log -p

git log -n 近n次提交的差异

git log --stat 列出提交的详细信息

git log --pretty 使用不同指定格式展现历史

--pretty=oneline 每次提交放在一行显示

git log 常用选项

选项 说明

-p 按补丁格式显示每个更新之间的差异。

--stat 显示每次更新的文件修改统计信息。

--shortstat 只显示 --stat 中最后的行数修改添加移除统计。

--name-only 仅在提交信息后显示已修改的文件清单。

--name-status 显示新增、修改、删除的文件清单。

--abbrev-commit 仅显示 SHA-1 的前几个字符,而非所有的 40 个字符。

--relative-date 使用较短的相对时间显示(比如,"2 weeks ago")。

--graph 显示 ASCII 图形表示的分支合并历史。

--pretty 使用其他格式显示历史提交信息。可用的选项包括 oneline,short,full,fuller 和format(后跟指定格式)。

git log --pretty=format 常用的选项

选项 说明

%H 提交对象(commit)的完整哈希字串

%h 提交对象的简短哈希字串

%T 树对象(tree)的完整哈希字串

%t 树对象的简短哈希字串

%P 父对象(parent)的完整哈希字串

%p 父对象的简短哈希字串

%an 作者(author)的名字

%ae 作者的电子邮件地址

%ad 作者修订日期(可以用 --date= 选项定制格式)

%ar 作者修订日期,按多久以前的方式显示

%cn 提交者(committer)的名字

%ce 提交者的电子邮件地址

%cd 提交日期

%cr 提交日期,按多久以前的方式显示

%s 提交说明

撤销操作

git commit --amend

打标签

git tag

推送

git push

别名

git config --global

分支切换

git checkout

解题

关卡提示:

有一个git存储库位于ssh://bandit30-git@localhost/home/bandit30 git/repo通过端口2220。用户bandit30git的密码与用户bandit30的密码相同。

克隆存储库并查找下一级别的密码。

bash 复制代码
```bash
bandit30@bandit:~$ mkdir /tmp/bdit30
bandit30@bandit:~$ cd /tmp/bait30
-bash: cd: /tmp/bait30: No such file or directory
bandit30@bandit:~$ cd /tmp/bdit30
bandit30@bandit:/tmp/bdit30$ git clone ssh://bandit30-git@localhost:2220/home/bandit30-git/repo
Cloning into 'repo'...
The authenticity of host '[localhost]:2220 ([127.0.0.1]:2220)' can't be established.
ED25519 key fingerprint is SHA256:C2ihUBV7ihnV1wUXRb4RrEcLfXC5CXlhmAAM/urerLY.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Could not create directory '/home/bandit30/.ssh' (Permission denied).
Failed to add the host to the list of known hosts (/home/bandit30/.ssh/known_hosts).
                         _                     _ _ _
                        | |__   __ _ _ __   __| (_) |_
                        | '_ \ / _` | '_ \ / _` | | __|
                        | |_) | (_| | | | | (_| | | |_
                        |_.__/ \__,_|_| |_|\__,_|_|\__|


                      This is an OverTheWire game server.
            More information on http://www.overthewire.org/wargames

bandit30-git@localhost's password:

remote: Enumerating objects: 4, done.

remote: Counting objects: 100% (4/4), done.

remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0

Receiving objects: 100% (4/4), done.

查看README.md没有结果

```bash
bandit30@bandit:/tmp/bdit30/repo$ ls
README.md
bandit30@bandit:/tmp/bdit30/repo$ cat README.md
just an epmty file... muahaha

尝试几次无果

bash 复制代码
bandit30@bandit:/tmp/bdit30/repo$ git log
commit d39631d73f786269b895ae9a7b14760cbf40a99f (HEAD -> master, origin/master, origin/HEAD)
Author: Ben Dover <noone@overthewire.org>
Date:   Thu Oct 5 06:19:45 2023 +0000

    initial commit of README.md
bandit30@bandit:/tmp/bdit30/repo$ git checkout ^C
bandit30@bandit:/tmp/bdit30/repo$ git log origin/master
commit d39631d73f786269b895ae9a7b14760cbf40a99f (HEAD -> master, origin/master, origin/HEAD)
Author: Ben Dover <noone@overthewire.org>
Date:   Thu Oct 5 06:19:45 2023 +0000

    initial commit of README.md
bandit30@bandit:/tmp/bdit30/repo$ ls
README.md
bandit30@bandit:/tmp/bdit30/repo$ cat README.md
just an epmty file... muahaha
bandit30@bandit:/tmp/bdit30/repo$ GIT LOG
GIT: command not found
bandit30@bandit:/tmp/bdit30/repo$ git log
commit d39631d73f786269b895ae9a7b14760cbf40a99f (HEAD -> master, origin/master, origin/HEAD)
Author: Ben Dover <noone@overthewire.org>
Date:   Thu Oct 5 06:19:45 2023 +0000

    initial commit of README.md
bandit30@bandit:/tmp/bdit30/repo$ git checkout origin/HEAD
Note: switching to 'origin/HEAD'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at d39631d initial commit of README.md
bandit30@bandit:/tmp/bdit30/repo$ ls -al
total 16
drwxrwxr-x 3 bandit30 bandit30 4096 Jan 19 11:50 .
drwxrwxr-x 3 bandit30 bandit30 4096 Jan 19 11:50 ..
drwxrwxr-x 8 bandit30 bandit30 4096 Jan 19 11:56 .git
-rw-rw-r-- 1 bandit30 bandit30   30 Jan 19 11:50 README.md
bandit30@bandit:/tmp/bdit30/repo$ cat README.md
just an epmty file... muahaha
bandit30@bandit:/tmp/bdit30/repo$ cd ./.git/
bandit30@bandit:/tmp/bdit30/repo/.git$ ls
branches  config  description  HEAD  hooks  index  info  logs  objects  packed-refs  refs
bandit30@bandit:/tmp/bdit30/repo/.git$ cat config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = ssh://bandit30-git@localhost:2220/home/bandit30-git/repo
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
bandit30@bandit:/tmp/bdit30/repo/.git/refs/remotes/origin$ cat HEAD
ref: refs/remotes/origin/master
bandit30@bandit:/tmp/bdit30/repo/.git/refs/remotes/origin$ cd ..
bandit30@bandit:/tmp/bdit30/repo/.git/refs/remotes$ ls
origin

看看标签,呵呵竟然找到了

bash 复制代码
bandit30@bandit:/tmp/bdit30/repo$ git tag
secret
bandit30@bandit:/tmp/bdit30/repo$ git tag show
bandit30@bandit:/tmp/bdit30/repo$ git tag show secret
fatal: tag 'show' already exists
bandit30@bandit:/tmp/bdit30/repo$ git show secret
OoffzGDlzhAlerFJ2cAiz1D41JW1Mhmt
相关推荐
一颗花生米。2 小时前
深入理解JavaScript 的原型继承
java·开发语言·javascript·原型模式
问道飞鱼2 小时前
Java基础-单例模式的实现
java·开发语言·单例模式
学习使我快乐012 小时前
JS进阶 3——深入面向对象、原型
开发语言·前端·javascript
通信仿真实验室3 小时前
(10)MATLAB莱斯(Rician)衰落信道仿真1
开发语言·matlab
勿语&3 小时前
Element-UI Plus 暗黑主题切换及自定义主题色
开发语言·javascript·ui
吾爱星辰7 小时前
Kotlin 处理字符串和正则表达式(二十一)
java·开发语言·jvm·正则表达式·kotlin
ChinaDragonDreamer7 小时前
Kotlin:2.0.20 的新特性
android·开发语言·kotlin
IT良7 小时前
c#增删改查 (数据操作的基础)
开发语言·c#
hengzhepa7 小时前
ElasticSearch备考 -- Async search
大数据·学习·elasticsearch·搜索引擎·es
Kalika0-08 小时前
猴子吃桃-C语言
c语言·开发语言·数据结构·算法