Git常用命令

发布于 2021-12-13  600 次阅读


初始化工作目录

git init

创建git对象

git hash-object -w object.txt

查看所有git对象

find .git/objects -type f

文件的检查和查看

git cat-file -p <key> 		# 查看对象内容信息
git cat-file -t <key> 		# 查看对象类型

往暂存区添加一条记录,让git对象对应上文件名

git update-index --add --cacheinfo <key> object.txt

通过暂存区创建树对象

git write-tree

提交树对象

echo 'first commit' | git commit-tree <key>

综合命令

查看暂存区

git ls-files -s

查看当前状态

git status
查看文件状态:
git diff

将当前目录放入暂存区,并且生成对象

git add ./

提交修改(加入-a参数后无需git add;改操作仅对修改、删除的 非新文件 有效)

git commit -m -a "secondFile"

提交生成的树对象

git commit -m 'firstFile'

创建分支并指向某次提交对象

git branch branchName <key>

查看分支

git branch

创建并切换到一个分支

git checkout -b branchName

切换分支

git checkout branchName

在当前提交对象上创建分支

git branch branchName

复制分支

git branch newName oldName

删除分支

git branch -d branchName
强制删除分支:
git branch -D branchName

查看提交记录

git log --oneline

查看未提交的暂存

git log --cache

查看整个项目的分支历史

git log --oneline --decorate --graph --all

别名

git config --global alias.allbranch "log --oneline --decorate --graph --all"
使用时:
git allbranch