1. 命令

1.1. 修改全局

1
2
3
4
5
6
7
8
9
//Date:   Thu Aug 16 17:44:32 2018 +0800
//Date: 2018-08-23T17:16:39+08:00

//修改当前仓库log date格式
git config log.date iso-strict-local

//全局设置log date格式
git config --global log.date iso-strict-local

2. 拉取推送

2.1. 拉取远程fork分支的修改

1
2
3
4
5
6
7
git remote add upstream https://gitee.com/LiuKewenSc/kewen-vue-admin.git
git fetch upstream

git merge upstream/master # 或者rebase

git push

引用

2.2. 日志 git log相关

1
2
3
git log 

git log --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(用来定义自己的格式)
–oneline –pretty=oneline –abbrev-commit 合用的简写

2.2.1. git log 的format格式

1
2
3
4
git log --pretty=format:"%h - %an, %ad : %s"
git log --date=format:"%Y-%m-%d\ %H:%M:%S"
git log --date=iso
git log --date=short
选项 说明
%H 提交的完整哈希值
%h 提交的简写哈希值
%T 树的完整哈希值
%t 树的简写哈希值
%P 父提交的完整哈希值
%p 父提交的简写哈希值
%an 作者名字
%ae 作者的电子邮件地址
%ad 作者修订日期(可以用 –date=选项 来定制格式)
%ar 作者修订日期,按多久以前的方式显示
%cn 提交者的名字
%ce 提交者的电子邮件地址
%cd 提交日期
%cr 提交日期(距今多长时间)
%s 提交说明

git stash 临时保存

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 保存当前未commit的代码
git stash

# 保存当前未commit的代码并添加备注
git stash save "备注的内容"

# 列出stash的所有记录
git stash list

# 删除stash的所有记录
git stash clear

# 应用最近一次的stash
git stash apply

# 应用最近一次的stash,随后删除该记录
git stash pop

# 删除最近的一次stash
git stash drop

3. 场景

3.1. 批量修改提交

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 切回到第一个提交
git rebase -i --root
# 修改弹出内容 ----- 修改pick为edit
pick 7d571cc commit 1
pick 77f0c04 commit2fdaff
pick a5a8e8a commit3aa333
# ------------------

# 重新commit
GIT_COMMITTER_DATE="2023-06-03T19:12:21" git commit --amend --date="2023-06-02T19:45:12"
GIT_COMMITTER_DATE="2024-06-14T19:51:03" git commit --date="2024-06-14T19:51:03"

#执行下一次提交
git rebase --continue

# 一直循环直到已经修改完

# 强制推送
git push -f origin main

Hbuderx参考