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
相关推荐
weixin_307779131 小时前
Hive集群之间迁移的Linux Shell脚本
大数据·linux·hive·bash·迁移学习
Coding小公仔2 小时前
C++ bitset 模板类
开发语言·c++
大只鹅2 小时前
解决 Spring Boot 对 Elasticsearch 字段没有小驼峰映射的问题
spring boot·后端·elasticsearch
小赖同学啊2 小时前
物联网数据安全区块链服务
开发语言·python·区块链
shimly1234562 小时前
bash 脚本比较 100 个程序运行时间,精确到毫秒,脚本
开发语言·chrome·bash
IT_10242 小时前
Spring Boot项目开发实战销售管理系统——数据库设计!
java·开发语言·数据库·spring boot·后端·oracle
new_zhou3 小时前
Windows qt打包编译好的程序
开发语言·windows·qt·打包程序
ye903 小时前
银河麒麟V10服务器版 + openGuass + JDK +Tomcat
java·开发语言·tomcat
武昌库里写JAVA3 小时前
Oracle如何使用序列 Oracle序列使用教程
java·开发语言·spring boot·学习·课程设计