1、查看commit信息
git log //查看完整提交历史信息
git show //查看最近一次提交的完整信息
git show [commit_id] 查看某次历史提交信息的完整信息
git show HEAD查看HEAD标签当前指向的提交的完整信息
git show master 查看master分支最新一次提交的完整信息
2、删除分支
git branch -d 分支名 //删除本地分支
git push origin --delete [branchname] //删除远程分支
3、修改commit信息
(1)git commit --amend //修改commit的描述信息, 只能用git push --force同步到远程
(2)git rebase origin/develop -i 修改commit版本信息
将pick->f:将f以后包含f的commit合并成一个
合并后强推至分支上git push origin 远程分支 -f
git rebase origin/develop -i 是指在origin/develop拉取之后的commit记录
# Commands:
# p, pick <commit> = use commit 确定提交
# r, reword <commit> = use commit, but edit the commit message 给予再一次编辑commit消息的机会
# e, edit <commit> = use commit, but stop for amending 提交,不允许修改
# s, squash <commit> = use commit, but meld into previous commit 合并提交,但保留所有的commit 信息
# f, fixup <commit> = like "squash", but discard this commit's log message 合并提交,只保留一个commit 信息
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
https://blog.csdn.net/the_power/article/details/104651772
4、拉取代码
git pull可以理解为:
git fetch origin master //从远程主机的master分支拉取最新内容
git merge FETCH_HEAD //将拉取下来的最新内容合并到当前所在的分支中
git fetch //拉去最新的代码
git cherry-pick // 对于多分支的代码库,将代码从一个分支转移到另一个分支是常见需求。这时分两种情况。一种情况是,你需要另一个分支的所有代码变动,那么就采用合并(git merge)。另一种情况是,你只需要部分代码变动(某几个提交),这时可以采用 Cherry pick
总结:git fetch只是把代码拉取到本地的远程副本
git pull 把分支拉取到本地的副本在与本地的进行合并
5、撤销操作
(1)git checkout . //撤销工作区的代码(未add)
(2)git reset HEAD //撤销缓冲区的代码(未commit)
git reset命令既可以回退版本,也可以把暂存区的修改回退到工作区。当我们用HEAD时,表示最新的版本。
(3)git 恢复到指定版本(未push)
1、查看git的提交版本和id 拿到需要恢复的版本号
命令:git log
2. 恢复到指定版本
命令:git reset --hard 44f994dd8fc1e10c9ed557824cae50d1586d0cb3 //后面这一大串44f994dd8fc1e10c9ed557824cae50d1586d0cb3就是版本id
3. 强制push
命令:git push -f origin maste
6、删除文件
git rm filename //删除本地和暂缓中的文件
git rm filename --cached //只删除缓存区中的内容
7、创建WIP分支
WIP= Work in Progress
研发中的代码想存储起来,但是又避免研发中的代码被合并,开发就会创建一个WIP
的分支
WIP MR
WIP MR
含义是 在工作过程中的合并请求,是一个我们在 GitLab 中避免 MR 在准备就绪前被合并的技术。只需要添加 WIP: 在 MR 的标题开头
,它将不会被合并,除非你把 WIP: 删除。
当你改动已经准备好被合并,编辑工单来手动删除 WIP:
,或者使用就像如下 MR 描述下方的快捷方式。
https://blog.csdn.net/lelemom/article/details/85960264
git rebase 成功之后撤销
首先执行git reflog查看本地记录
可知本次rebase之前的id 为:
02a3260 HEAD@{9}: commit: adjust ds5 ir data save file formate
所以执行
git reset --hard 02a3260
即可
https://blog.csdn.net/chengde6896383/article/details/83418488