27

当我在“开发”分支上进行更改时,我会在分支旁边看到一个向上箭头,告诉我将推送多少更改。让我感到困惑的是 sourcetree 如何决定数字是多少?

它似乎与一种叫做帅哥的东西有关?什么是帅哥?

是否有一个等效的 git commit 返回相同的数字?

4

3 回答 3

20

请注意,要推送的更改数量可能是指您在 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

如果您想计算它,只需执行以下操作:

mb=...
git log --pretty=oneline $mb..HEAD | wc -l

hunk是一个与 相关的术语diff

该格式以与上下文格式相同的两行标题开头,不同之处在于原始文件以“---”开头,新文件以“+++”开头。在此之后是一个或多个包含文件中行差异的更改块。未更改的上下文行前面有一个空格字符,添加行前面有一个加号,删除行前面有一个减号。

如果您曾经对两个文件进行比较,您会看到这样的文件(再次来自维基百科):

--- /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.

上面的文件有三个大块。如果您想查看与提交相关的差异,可以使用git show [<commit>]. 要查看当前未暂存更改与存储库之间的差异,您可以使用git diff. 还有各种其他选择。

要计算帅哥的数量(这真的,真的没用,但如果你坚持的话),你可以使用一个非常简单的脚本。

git show | grep '^@@.*@@.*$' | wc -l

.*第二个之后的原因@@是 git 的 diff 还显示了更改所属的函数,以便以后可以更好地应用 diff,因此大块标题可能如下所示:

@@ -85,6 +85,6 @@ void urt_shmem_detach(void *mem)
于 2013-08-01T13:23:47.300 回答
9

在回答大块头问题时:

Hunk means a piece of change in the Git world.

来源:https ://mvtechjourney.wordpress.com/2014/08/01/git-stage-hunk-and-discard-hunk-sourcetree/

有建议

将“hunk”替换为“change”,跟随 Git 变得很愉快。

于 2017-11-22T10:07:11.363 回答
2

要推送的更改数量基本上是您自上次推送以来所做的提交数量。Sourcetree 通过在提交方面查看远程头和当前头之间的距离来计算这一点。

git status将告诉您您领先的提交数量(= 将被推送的提交数量):

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.

这与大块没有太大关系,大块是单独的差异。

于 2013-08-01T13:17:11.320 回答