如何从当前分支获取已提交文件的提交和更改?
Posted
技术标签:
【中文标题】如何从当前分支获取已提交文件的提交和更改?【英文标题】:How to get commits and changes in committed files from current branch? 【发布时间】:2021-12-04 02:06:27 【问题描述】:我使用如下查询:
git cherry -v feature/Mappers feature/samples/Automapper
这使我能够获得所需的数字和提交。像这样:
+ 54ee7b846897b0221920140fae12518877788684 Add initial web project for automapper.
+ 707aff03cb8baef0d67ab6304b2f64cfbd54fc1c Delete useless usings.
+ cd2d8acf843c4ec57f4c05a01c14bc53e13c76da Add package for Automapper.
+ 89d063052723977bf5b73a630941bd920c7d3b7b Configure middleware for automapper usage.
+ a5086f947df333e702c7794dc287ef84e0b7343e Add base model for dal layer.
+ 11ac745e252a7ca8b47ca19322df02c9569a85ea Add user model for ui layer.
+ dcb042a4a0b7c4b6eaed679f239023e176c45730 Rename dto model.
+ 95ce33de2d2370e9849ae684d56fb1a92ecf6fcb Add controller, service, interface.
+ 22e71bf78c4e519fe7c6b0b8d32d3650eebf0ee4 Add models for layers.
+ a7f105b9d5f0d24a8c3560e1413280692f0e24e5 Add contexts for database.
+ 03e2c7cf22cb93a286b2f07fb38feee906e664ce Add mapping profile.
+ e1c480606522f70471bf52562cd950bc45f1fb39 Add automapper, swagger, dbcontext to middleware.
+ 750e987057503a534da6c5547e18b753720cd9ab Add connection string to appsettings.
+ d9b66db789df46460a7e3a987cff652c0105661c Add packages.
但不输出文件更改。
我怎样才能不仅从当前分支的已提交文件中获取提交,还获取更改?
【问题讨论】:
这能回答你的问题吗? What does cherry-picking a commit with Git mean? 【参考方案1】:git-show
命令可以帮助您解决这个问题,它会打印出特定哈希的提交以及其中所做的更改。
例如这是git show
的输出(默认HEAD
):
commit 6ac439bd518be4c0845f9508f06d69f0cb90c82b (HEAD -> master, origin/master, origin/HEAD)
Author: Your-name <Your@email.com>
Date: Thu Oct 14 21:18:37 2021 -0500
Your commit message
diff --git a/describe.c b/describe.c
index fabadb8..cc95eb0 100644
--- a/describe.c
+++ b/describe.c
@@@ -98,20 -98,12 +98,20 @@@
return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
- static void describe(char *arg)
-static void describe(struct commit *cmit, int last_one)
++static void describe(char *arg, int last_one)
+ unsigned char sha1[20];
+ struct commit *cmit;
struct commit_list *list;
static int initialized = 0;
struct commit_name *n;
+ if (get_sha1(arg, sha1) < 0)
+ usage(describe_usage);
+ cmit = lookup_commit_reference(sha1);
+ if (!cmit)
+ usage(describe_usage);
+
if (!initialized)
initialized = 1;
for_each_ref(get_name);
【讨论】:
好的,谢谢,git log 也可以,但是如何排除索引等额外信息呢? @@@ -98,20 -98,12 +98,20 @@@ 以更好地查看所需信息。 它还打印索引以上是关于如何从当前分支获取已提交文件的提交和更改?的主要内容,如果未能解决你的问题,请参考以下文章