![](/img/trans.png)
[英]Git is it possible to revert a wrong pull or push only chosen commit?
[英]Is it possible to 'git pull' only the next commit?
我知道git pull
会将工作分支更新到它跟踪的远程分支的尖端。 所以假设如果我执行git pull
,它将拉入所有最新的更改。 就我而言,它将在我的树的顶部进行 5 处更改。
有没有办法git pull
一个零钱? 即,如果git pull
会将零钱 03、04、05、06 和 07 放在我的树的顶部,我如何只拉零钱 03? 在执行此命令时,我不知道它将引入的下一个更改的提交 ID。
我的树的尖端完全没有改变,不会有任何合并冲突等。
也许是这样的?
git fetch
git merge <commit to merge>
要查找要合并的提交的 ID,请在运行提取后在 gitk 中查找它。
这在理论上应该是可能的。 git status
显示有 8 个提交要提取,如果脚本可以解析出“8”并为您想要的下一次提交数输入(默认为 1)。 你可以运行git-pull-next 2
它可以这样做:
newCommits
pullNextNCommits
,等于 cli 输入,默认为 1newCommits
之前的提交 hash,减去pullNextNCommits
current_git_branch
存储为git rev-parse --abbrev-ref HEAD
结果git checkout <hash>
git checkout -b current_git_branch
多田。 不是不可能。 只需要写这个脚本...
这个答案是一个社区 wiki,请随意充实伪代码
可能有更好的方法来做到这一点——因为 git 拉合并可能有问题,最好从这里的第一个答案中获取灵感。 但不知何故,以编程方式找到下一个提交 hash。
你可以。 非常简单:
git fetch
git log --oneline --decorate --graph --all
git merge <some-commit-id>
#Repeat last line as often as you wish
#to incorporate upstream changes piecemeal.
git log
的标志组合对于快速了解发生的事情非常有用,以至于我总是定义一个 shell 别名来使用这个精确组合:
alias gitlog='git log --oneline --decorate --graph'
使用该别名,上述序列变为
git fetch
gitlog --all
git merge ...
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.