'git diff HEAD ^`的反义词是什么? [英] What is the opposite of `git diff HEAD^`?

查看:404
本文介绍了'git diff HEAD ^`的反义词是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在git中,我可以通过说 HEAD ^ HEAD〜1 来指定以前的版本。那么去其他方式呢?假设我在版本X上,并且执行 git checkout X ^


$ b 类似于 git checkout X +

解决方案

你无法真正做到这一点。 git中的历史记录是一个定向的非循环图 - 每个提交都包含对其父母的引用,但父母没有引用他们的孩子。



你考虑一个你创建多个分支的提交。你的意思是下一个承诺?和父母一起,你可以对数字进行编号(一个正常的合并提交有第一和第二个父母),但你如何与孩子做这件事?即使你知道你试图在哪个分支上(例如,你已经签出了 master〜4 ,现在你想看看 master 〜3 )它没有明确定义 - 你可能会遇到这样的情况:

   - X(头) -  o  -  o  -  o  -  Y(主)
\ /
o - o - o ----------



也就是说,在简单的情况下,您可以这样做:

  git checkout $(git rev-list HEAD..master | tail -n 1)

显然,线性历史记录可以正常工作。通过合并... rev-list 可以从历史中的现在到过去,追溯它。我相信它跟在第一个父亲的第一个,所以最后打印的东西将是在 HEAD 后面的所有最后父母的提交。



编辑:这的确假设你知道你想向哪个分支前进。如果你不......好吧,你几乎停留在所有的refs上,以当前HEAD作为父对象的提交 - 可能会对 git rev-parse

  git rev-list --all --children | grep ^ $(git rev-parse HEAD)

然后从行中获取其他SHA1(使用awk , 随你)。您必须手动检查或作出任意选择,如果有多个结果...


In git, I can specify the previous revision by saying HEAD^ or HEAD~1. What about going the other way? Suppose I'm on revision X, and I do git checkout X^. How do I go back?

Something like git checkout X+?

解决方案

You can't really do precisely that. History in git is a directed acyclic graph - each commit contains references to its parents, but parents don't have references to their children.

The problem here should become obvious when you think about a commit you created multiple branches from. Which "next commit" do you mean? With parents, you can number off (a normal merge commit has a first and second parent), but how do you do that with children? Even if you know what branch you're trying to be on (e.g. you've checked out master~4 and now you want to look at master~3) it's not well-defined - you could be in a situation like this:

- X (HEAD) - o - o - o - Y (master)
   \                    /
    o - o - o ----------

That said, in simple cases, you could do something like this:

git checkout $(git rev-list HEAD..master | tail -n 1)

Clearly that'll work fine with linear history. With merges... rev-list works from present to past in the history, following it backward. I believe it follows the first parent first, so the thing printed last will be the commit after HEAD found by following all last parents.

Edit: That does assume that you know which branch you want to move forward toward. If you don't... well, you're pretty much stuck looking on all refs for commits which have the current HEAD as parent - probably grepping the output of git rev-parse:

git rev-list --all --children | grep ^$(git rev-parse HEAD)

Then grab the other SHA1 from the line (use awk, whatever). You'll have to manually inspect or make an arbitrary choice if there are multiple results though...

这篇关于'git diff HEAD ^`的反义词是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆