git 如何区分git标签和分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38004144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to diff between git tag and branch
提问by Amos Shapira
While trying to understand the difference between the HEAD of Appium 1.4 branch and tag v1.4.16, I didn't find a way to tell git diff to differentiate between the tag and the branch.
在试图理解 Appium 1.4 分支的 HEAD 和标签 v1.4.16 之间的区别时,我没有找到一种方法来告诉 git diff 区分标签和分支。
As far as I understand, from git diff's perspective, both the tag and the branch are just aliases to a commit hash, aren't they?
据我所知,从 git diff 的角度来看,标签和分支都只是提交哈希的别名,不是吗?
I eventually just created tag 'v1.4' pointing to the branch head (git checkout 1.4; git tag -a v1.4
) and then I could do git diff v1.4.16..v1.4
and see the difference I was after.
我最终只是创建了指向分支头 ( git checkout 1.4; git tag -a v1.4
) 的标签“v1.4” ,然后我可以做git diff v1.4.16..v1.4
并看到我所追求的差异。
But this seems a bit strange, is this the only way to achieve what I needed?
但这似乎有点奇怪,这是实现我所需要的唯一方法吗?
回答by Amos Shapira
Thanks everyone for the leading suggestions. The issue seems to be that I didn't have a local branch 1.4
. I could achieve what I wanted (i.e. diff between the tag and the branch head on the original Git repo) in a couple of ways:
感谢大家的主要建议。问题似乎是我没有本地分支1.4
。我可以通过以下几种方式实现我想要的(即原始 Git 存储库上的标签和分支头之间的差异):
- Switch to it (with
git checkout 1.4
), then I could dogit diff v1.4.16
- Refer to it on the remote:
git diff v1.4.16..origin/1.4
- 切换到它(用
git checkout 1.4
),然后我就可以了git diff v1.4.16
- 在遥控器上参考它:
git diff v1.4.16..origin/1.4
Both achieved what I wanted.
两者都达到了我想要的。