文章目录
在此记录git 使用的一些有用的用法,持续更新!
将一个commit打一个patch,用于测试更早的commit是否有问题
git log 查看commit
git format-patch -1 -o ./ 打1个patch在本地
git reset --hard {commit_num} 切换到想到的commit
git status 查看步骤2打的patch
git am {patch_name} 加载patch名称
git apply {patch} --reject
vim {file}.rej
git add -u
git am --resolved
git remote的使用
一个无法链接外网的环境和一台可以链接外网的环境怎么使的无法链接外网的环境可以更新仓库。
git remote add {name} {path}
在本地的仓库名字、在远端的地址
git fetch {name}
git branch -a
git 查看谁删除了一个文件
git log --name-status
搜索文件路径
同一个branch上多个commit提交review
一起提交
git reivew -r origin {remote}
修改中间的一个commit :根据提示如果要修改就将pick改为edit.
git rebase -i HEAD~2
pick 3278d34 librbd: don't flush when rbd is busy
pick 8a0b2d7 rbd: introduce rbd_global_cache_size to limit the global cache size in one node
# Rebase e4ca829..8a0b2d7 onto e4ca829
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
修改文件之后提交
git commit --amend
git rebase --continue
如果有冲突解决冲突
将社区的分支Push到自己搭建的仓库中
clone 自己搭建的仓库到本地
git clone ssh://……
在刚刚clone下来的本地仓库增加社区的仓库地址
git remote add {name} https://……
将社区分支的代码fetch到本地
git fetch {name}
切换到需要的分支,如
git checkout -b V12.2.12 v12.2.12
将这个分支push到自己的远程仓库,如
git push origin V12.2.12:new-12.2.12
将社区更高版本的一个patch cherry-pick到本地的仓库中分支并提交高仓库
在本地仓库增加社区的仓库地址
git remote add {branchname} https://……
将社区仓库对用的分支fetch到本地仓库
git fetch sqceph luminous:locallu
找到patch对应的commit号并cherry-pick
git cherry-pick 6be12f22a55ed3d179d1c93be1190a05fd03d80c