修改区(Changes):当修改了某个文件并保存之后,这个文件就会出现在修改区,表示此文件进行了修改
git status
git checkout .
git stash save [-a] "save message"
// 查看缓存区内容
$ git stash list
stash@{0}: On BM01: 719
stash@{1}: On BM01: 接口调试
stash@{2}: On BM01: NightMode UI2
stash@{3}: On BM01: NightMode UI
//恢复缓存区内容
git stash apply stash@{num}
//恢复缓存区内容并删除缓存区
git stash pop stash@{num}
//删除指定缓存区
git stash drop stash@{num}
//清空缓存区
git stash clear
git add FileName
暂存区(Staged):执行了git add之后,文件就会被放入暂存区
git add tmp.c
将tmp.c提交到了暂存区
如果发现tmp.c是不需要commit的,使用
git restore --staged tmp.c
将tmp.c从暂存区移除
git commit -m "注释说明"
git commit --amend
本地仓库(Local):执行了git commit之后,文件就会被放入本地仓库
接上一个例子,使用git comiit 将tmp.c提交到本地仓库
提交到本地仓库目前的节点
git commit --amend
提交到一个新节点
git commit -m "new commit message"
// 1
git checkout 上一个节点commitID 文件名
// 2
git commit --amend
git log [--raw]/[-p]
git push origin HEAD:refs/for/master
远程仓库(Remote):远程代码仓库(GitHub、Gitee等)
回到先前的第n个节点
git rebase -i HEAD~n
进入edit界面
pick 4a892af5 [BBM-102] 更多设置二级菜单 - 夜视模式设置功能开发
pick 1b01b03d [BBM-116] 幕休眠问题-自定义上建数值修改为1
# Rebase 028cf970..1b01b03d onto 028cf970 (2 commands)
#
# Commands:
# p, pick = use commit
对需要修改的节点进行修改为edit, 如下:
edit 4a892af5 [BBM-102] 更多设置二级菜单 - 夜视模式设置功能开发
pick 1b01b03d [BBM-116] 幕休眠问题-自定义上建数值修改为1
# Rebase 028cf970..1b01b03d onto 028cf970 (2 commands)
#
# Commands:
# p, pick = use commit
然后对节点进行修改提交
最后使用保存修改并回到当前节点
git rebase --continue
git pull --rebase
处理完冲突之后
git rebase --continue
git reset --hard
强制回到上一个节点,不保留内容
git reset --hard commitID
强制回到commitID,不保留内容
git reflog
git reset --soft HEAD^
回到上一个节点,保留内容
git reset --soft commitID
回到commitID节点,保留内容
git reflog
查看提交情况
git rebase --edit-todo
查看和编辑节点.
git restore --stage filename
使用
git add a b c d
git commit -m "commit1"
/*
commitID1 : 64418d4e06eb8cdefa30238b9baa276f1a61bb23
a
b
c
d
commitID2 : 64418d4e06eb8cdefa30238b9baa276f1a61bb24
A
B
C
D
*/
将暂存区的文件都提交到了本地仓库,但是发现文件中的d是没有修改过的,因此不需要将d推到远程仓库中,于是需要将本地仓库的d撤销.使用命令:
git checkout commitID2 -- file_path
git commit --amend
eg
user@DESKTOP-O6DNC0L MINGW64 /e/0710-BM01/Sonix-SN937x (BM01)
$ git log
commit 21822bb189de9607a8c7477f803d6b0b061e250f (HEAD -> BM01)
Author: maangang <[email protected]>
Date: Mon Jul 17 15:17:11 2023 +0800
[BBM-102] 更多设置菜单-夜视模式设置UI和功能开发
Change-Id: I9ac2ee4bf074a1f7ee1c50ea2ea6acce35e87434
commit a776d61b0eb85d2e0c4f1132a7467e54279a49ca (origin/BM01)
Author: liankun <[email protected]>
Date: Mon Jul 10 17:54:56 2023 +0800
[BBM-96] VOX 设置菜单的 UI 实现
Change-Id: I498dddb0c0b928f3abb4d72519b52b5189c1e324
commit a550ae84661c8c0b5ad65fa1b505c96182087623
Author: liankun <[email protected]>
Date: Mon Jul 10 17:54:56 2023 +0800
user@DESKTOP-O6DNC0L MINGW64 /e/0710-BM01/Sonix-SN937x (BM01)
$ git checkout a776d61b0eb85d2e0c4f1132a7467e54279a49ca -- ApkRes/OS
user@DESKTOP-O6DNC0L MINGW64 /e/0710-BM01/Sonix-SN937x (BM01)
$ git status
On branch BM01
Your branch is ahead of 'origin/BM01' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git restore --staged ..." to unstage)
modified: ApkRes/OSD_english.res
user@DESKTOP-O6DNC0L MINGW64 /e/0710-BM01/Sonix-SN937x (BM01)
$ git commit --amend
[BM01 1bef2dda] [BBM-102] 更多设置菜单-夜视模式设置UI和功能开发
Date: Mon Jul 17 15:17:11 2023 +0800
5 files changed, 198 insertions(+), 83 deletions(-)
user@DESKTOP-O6DNC0L MINGW64 /e/0710-BM01/Sonix-SN937x (BM01)
$ git commit --amend
[BM01 d2613fb6] [BBM-102] 更多设置-夜视模式设置功能开发
Date: Mon Jul 17 15:17:11 2023 +0800
5 files changed, 198 insertions(+), 83 deletions(-)
user@DESKTOP-O6DNC0L MINGW64 /e/0710-BM01/Sonix-SN937x (BM01)
git log --raw
user@DESKTOP-O6DNC0L MINGW64 /e/BM-01/Sonix-SN937x (BM-01)
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> BM-01
解决冲突
user@DESKTOP-O6DNC0L MINGW64 /e/BM-01/Sonix-SN937x (BM-01)
$ git branch --set-upstream-to=origin/BM01 BM-01
branch 'BM-01' set up to track 'origin/BM01'.