Git使用小结

ctf经常遇到git文件泄露的问题,最近系统的学习一下git,总结一下git常见的操作方法。

git工作流程

1
2
3
4
1. 在工作目录中添加、修改文件;
2. 将需要进行版本管理的文件放入暂存区域;
3. 将暂存区域的文件提交到 Git 仓库。
Git 管理的文件有三种状态:已修改(modified)、已暂存(staged)和已提交(committed)

初始配置

1
2
3
git config --global user.name "FishC_Service"
git config --global user.email "[email protected]"
git config --list

git基本使用

1
2
3
4
5
6
7
8
9
10
11
12
13
git init --创建git项目
git add README.md --将文件加入版本控制
git commit -m "add a readmefile" --提交到git仓库
git commit --amend -m "add a readmefile" --更正最后一次提交
git status --查看当前提交状态
git reset HEAD <file> --最近提交到git仓库的恢复到暂存区
git reset HEAD~ --版本回滚,上一个快照,~~或者~2为上两个快照
git reset --soft HEAD~ --撤销上一次提交
git reset --hard HEAD~ --将所有区域回滚
git reflog --查看所有commit id,误删修复
git rm --删除暂存区和工作区文件
git rm --cached test.py --删除暂存区文件
git mv test.py game.pt --修改文件名

版本对比

1
2
3
4
5
6
git diff --比较暂存区与工作区
git diff ID1 ID2 --比较git仓库版本快照
git diff ID --比较当前工作目录与git仓库,ID=HEAD与最新git仓库比较
git diff --cached [ID] 比较暂存区与git仓库,ID可选
翻页操作:J下移,K上移。F页下移,B上移。D半页下移,U半页上移。3J代表移动三行
搜索命令:/或者?,/有上向下,?由下向上

git分支

1
2
3
4
5
6
7
8
git branch feature --创建分支
git branch -D feature --删除分支
git branch feature 3eac14d05bc1264cda54 --恢复分支
git branch -a --查看分支列表
git checkout feature --切换到分支
git log --decorate --显示指向分支的所有引用,标签 all 显示所有 graph 图形显示 oneline 精简显示
gir merge feature --将feature合并到当前分支
git checkout -b feature2 --创建并切换到分支

git文件

1
2
3
4
git ls-files --查看所有跟踪文件
git ls-files -s -- index.php //查看具体信息
git cat-file -p dfcd42 //查看内容
git log --pretty=oneline

GitHub

1
ssh -T [email protected] //是否连接成功
1
2
git remote add origin [email protected]:yourName/yourRepo.git
//后面的yourName和yourRepo分别是你的github的用户名和刚才新建的仓库名。
1
2
git remote add origin [email protected]:yourName/yourRepo.git
//连接远程主机
1
2
git push origin <branch> 
//将分支push到远程仓库
1
2
git push -uf origin master 
//-u参数是设置本地仓库默认的upstream,-f强制
1
2
3
//提交
git remote add origin https://github.com/ttonys/docker.git
git push -u origin master
1
git pull --rebase origin master --与本地仓库合并
Author: Sys71m
Link: https://www.sys71m.top/2018/03/20/Git使用小结/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.