git 大块头对于 sourcetree 上的推送意味着什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17995092/
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
What does a hunk mean in relation to pushes on sourcetree
提问by Breako Breako
When I make changes on my "develop" branch, I see an up-arrow beside the branch telling me how many changes will be pushed. What confuses me thou is how sourcetree decides what the number is?
当我在“开发”分支上进行更改时,我会在分支旁边看到一个向上箭头,告诉我将推送多少更改。让我困惑的是 sourcetree 如何决定数字是多少?
It seems to relate to something called hunks? What are hunks?
它似乎与一种叫做帅哥的东西有关?什么是帅哥?
Is there an equiavalent git commit which returns the same number?
是否有等效的 git commit 返回相同的数字?
采纳答案by Shahbaz
Note that the number of changes to be pushed probably refers to number of commits you are ahead of origin/master and is unrelated to hunks. To see the commits you are ahead of master, you can do the following:
请注意,要推送的更改数量可能是指您领先于 origin/master 的提交数量,并且与大块头无关。要查看您领先于 master 的提交,您可以执行以下操作:
# get most recent commit found in both master and origin/master
mb=$(git merge-base master origin/master)
# show commits from that merge base to current head
git log $mb..HEAD
If you want to count it, simply do:
如果您想计算它,只需执行以下操作:
mb=...
git log --pretty=oneline $mb..HEAD | wc -l
hunk
is a term related to diff
:
hunk
是一个与以下相关的术语diff
:
The format starts with the same two-line header as the context format, except that the original file is preceded by "---" and the new file is preceded by "+++". Following this are one or more change hunksthat contain the line differences in the file. The unchanged, contextual lines are preceded by a space character, addition lines are preceded by a plus sign, and deletion lines are preceded by a minus sign.
该格式以与上下文格式相同的两行标题开头,只是原始文件前面带有“---”,新文件前面带有“+++”。在此之后是一个或多个变帅哥包含文件中的行差异。未更改的上下文行以空格字符开头,添加行以加号开头,删除行以减号开头。
If you have ever taken a diff of two files, you see the file like this (again from wikipedia):
如果你曾经对两个文件进行过比较,你会看到这样的文件(再次来自维基百科):
--- /path/to/original ''timestamp'' +++ /path/to/new ''timestamp'' @@ -1,3 +1,9 @@ +This is an important +notice! It should +therefore be located at +the beginning of this +document! + This part of the document has stayed the same from version to @@ -5,16 +11,10 @@ be shown if it doesn't change. Otherwise, that would not be helping to -compress the size of the -changes. - -This paragraph contains -text that is outdated. -It will be deleted in the -near future. +compress anything. It is important to spell -check this dokument. On +check this document. On the other hand, a misspelled word isn't the end of the world. @@ -22,3 +22,7 @@ this paragraph needs to be changed. Things can be added after it. + +This paragraph contains +important new additions +to this document.
--- /path/to/original ''timestamp'' +++ /path/to/new ''timestamp'' @@ -1,3 +1,9 @@ +This is an important +notice! It should +therefore be located at +the beginning of this +document! + This part of the document has stayed the same from version to @@ -5,16 +11,10 @@ be shown if it doesn't change. Otherwise, that would not be helping to -compress the size of the -changes. - -This paragraph contains -text that is outdated. -It will be deleted in the -near future. +compress anything. It is important to spell -check this dokument. On +check this document. On the other hand, a misspelled word isn't the end of the world. @@ -22,3 +22,7 @@ this paragraph needs to be changed. Things can be added after it. + +This paragraph contains +important new additions +to this document.
The file above has three hunks. If you want to see the diff associated with a commit, you can use git show [<commit>]
. To see the diff between your current unstaged changes and the repository, you can use git diff
. There are various other options.
上面的文件有三个大块头。如果要查看与提交相关的差异,可以使用git show [<commit>]
. 要查看当前未暂存更改与存储库之间的差异,您可以使用git diff
. 还有各种其他选择。
To count the number of hunks (which is really, really useless, but if you insist), you can use a very simple script.
要计算帅哥的数量(这真的,真的没用,但如果你坚持的话),你可以使用一个非常简单的脚本。
git show | grep '^@@.*@@.*$' | wc -l
The reason for the .*
after the second @@
is that git's diff also shows the function the change belongs to so it can better apply the diff later, so the hunk heading could for example look like this:
.*
后面的原因@@
是 git 的 diff 还显示了更改所属的函数,以便以后可以更好地应用 diff,因此大块标题可能如下所示:
@@ -85,6 +85,6 @@ void urt_shmem_detach(void *mem)
回答by Dirk Schumacher
On answering the hunkquestion:
在回答大块头问题时:
Hunk means a piece of change in the Git world.
Hunk means a piece of change in the Git world.
src: https://mvtechjourney.wordpress.com/2014/08/01/git-stage-hunk-and-discard-hunk-sourcetree/
源代码:https: //mvtechjourney.wordpress.com/2014/08/01/git-stage-hunk-and-discard-hunk-sourcetree/
There is the suggestion of
有这样的建议
Replace the word ‘hunk' with ‘change' and it becomes pleasurable to follow Git.
用“变化”代替“大块头”这个词,跟随 Git 会变得很愉快。
回答by nneonneo
The number of changes to be pushed is basically the number of commits you've made since the last push. Sourcetree computes this by looking at the distance between the remote head and the current head in terms of commits.
要推送的更改数量基本上是您自上次推送以来所做的提交数量。Sourcetree 通过在提交方面查看远程头和当前头之间的距离来计算这一点。
git status
will tell you the number of commits you're ahead (= number of commits that will be pushed):
git status
会告诉你你领先的提交数量(= 将被推送的提交数量):
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
This doesn't have much to do with hunks, which are individual pieces of diffs.
这与大块头没有太大关系,大块头是差异的单个部分。