1.git add .
2.git commit -m '提交信息'
3.git pull origin 需要同步的远程分支 --rebase
如果有冲突解决冲突后
4.git add .
5.git rebase --continue
6.出来vim界面按:wq
如果还有冲突继续4-6,直到没有冲突后
执行3
然后执行git push -f
将多个 commit 合并成一个
- 找到自己的第一次commit的前一次commit,如果commit太多可以先找到自己的最早的commit,运行
git reset --soft 你commit
- 然后运行
add
,commit
- 运行
git log
查看commit记录自己的是不是只有一个了,如果不是的话,再次从1开始 git pull origin master —rebase 同步远程master
- git push -f
commit message 头
feat:新功能(feature)
fix:修补bug
docs:文档(documentation)
style: 格式(不影响代码运行的变动)
refactor:重构(即不是新增功能,也不是修改bug的代码变动)
test:增加测试
chore:改变构建流程、或者增加依赖库、工具等
perf: 优化相关,比如提升性能、体验
revert: 回滚到上一个版本
git 常用命令
- 删除远程文件,但不删除本地的
git rm -r --cached dist
- 覆盖上一次提交(刚提交完又有变动)
git commit -m 'message' --amend
- 展示某一个commit 的提交
HEAD 最新一次
git show HEAD(commitId)
把某一个项目的提交同步到另一个项目里
使用 patch
1). 在有你需要的 commit 的项目里使用
git format-patch commitid -n
n 某次提交(含)之前的几次提交,n 是1就是当前,n 是4,就是包含当前和之前的一共四次提交
运行后 会生成对应每次提交的一个 patch

然后将我们的生成的 patch 移动到需要同步过去的项目下,
运行
// 不运行可能会报 .git/rebase-apply still exists but mbox given.
git am --abort
git am *.patch
如果遇到报错
Applying: PACTH DESCRIPTION
error: patch failed: file.c:137
error: file.c: patch does not apply
error: patch failed: Makefile:24
error: libavfilter/Makefile: patch does not apply
Patch failed at 0001 PATCH DESCRIPTION
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort".
运行
git apply PATCH --reject
// 根据.rej文件手动解决所有冲突
git add .
git am --resolved
补充命令:
当前分支所有超前master的提交:
git format-patch -M master
从根到指定提交的所有patch:
git format-patch --root [commitId]
某两次提交之间的所有patch:
git format-patch [前面的commitId]..[后面的commitId]
将本地代码还原到最新的 commit
// 还原到 最新 commit
git stash
// 还原到你还原之前的代码
git stash pop
网友评论