【问题标题】:How can I extract filepaths and changes from a commit or pull request using git?如何使用 git 从提交或拉取请求中提取文件路径和更改?
【发布时间】:2020-03-06 16:49:56
【问题描述】:

我正在尝试从 Github 中的提交/拉取请求中获取更改的合并列表(文件路径和新/修改/删除的更改)。

这是我想要达到的格式:

filepath/to/some/file.properties:thisIsAKey=This is the string for this key.

我可以使用以下方法相对轻松地获取文件路径:

git show --pretty="format:" --name-only commitID

我也试过这个,但它包含很多噪音:

git log -p commitID

这是我使用上述内容的结果,但我只需要 b/+ 更改:

diff --git a/locales/ES/es/forms/dispute-options.properties b/locales/ES/es/forms/dispute-options.properties
index 490457e9e0..569921196a 100644
--- a/locales/ES/es/forms/dispute-options.properties
+++ b/locales/ES/es/forms/dispute-options.properties
@@ -60,4 +60,5 @@ fraudSeller.info=Para cancelar este pedido tendrá que comunicarse directamente
 fraudSeller.errorHeadingMessage = Lo sentimos, pero no puede reportar este tipo de problema para la transacción seleccionada.
 fraudSeller.backButtonText = Atrás

-modal.cancel=Cancel
\ No newline at end of file
+modal.cancel=Cancel
+disputeOptions.creditTransactionInfo=Si presenta un caso para esta compra, aún tendrá que continuar pagando cualquier saldo importe dejado en su plan de {data.pageStore.value.creditProductDescriptor} junto con la comisiones tardía (si corresponde).

我一直在阅读有关如何使用 diff-filter 的文档,但还没有看到任何符合我需要的内容。

编辑: 感谢大家的cmets!它让我找到了我正在寻找的答案:git diff -U0 --ignore-all-space commitID1 commitID2 | grep '^[+]' | grep -Ev '^(--- a/)' > test.txt

【问题讨论】:

  • 这行得通吗? git log --name-status --pretty="" <COMMIT_ID>

标签: git github git-log git-show


【解决方案1】:

鉴于您正在谈论 PR(这可能意味着许多修订,而不仅仅是一个),我认为您必须尝试:

git diff --name-only base-branch...pr-branch

注意三个点

这应该会给你添加/删除/修改文件的列表。

【讨论】:

  • ..... 是什么?我一直使用..。包括在内吗?
  • .. 表示两个分支的区别。所以...您想检查 PR 引入的更改。那挺好的。如果您从 开始的分支没有 移动,那么您将使用 ..... 从 PR 获取更改...但是如果基础分支 搬家了?然后你从 PR 中获得更改...加上由于 2 个分支分歧而在基础分支上引入的更改。如果您想要的是 PR only 引入的更改,那么您必须使用三点。然后 git 会检查分支在哪里发散,然后从那里区分。
  • 有趣。我过去曾使用git merge-base 来实现这一目标。
  • 然后从那里区分?当然可以....只有... 会为您执行此操作。
猜你喜欢
  • 2011-05-05
  • 2011-11-13
  • 1970-01-01
  • 2020-06-09
  • 1970-01-01
  • 2018-01-19
  • 2017-08-30
  • 2016-02-05
  • 1970-01-01
相关资源
最近更新 更多