启动一个新的存储库并添加一些提交:
#( 03/01/17@10:50am )( tim@tim ):~
mkdir test && cd test && git init
Initialised empty Git repository in /home/tim/test/.git/
.
#( 03/01/17@11:17am )( tim@tim ):~/test@master✔
touch readme && git add --all && git commit -am "readme"
[master (root-commit) 1b7f299] readme
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 readme
.
#( 03/01/17@11:17am )( tim@tim ):~/test@master✔
touch howto && git add --all && git commit -am "howto"
[master fd46c4c] howto
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 howto
.
#( 03/01/17@11:19am )( tim@tim ):~/test@master✔
touch la && git add --all && git commit -am "add la"
[master 4680089] add la
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 la
.
#( 03/01/17@11:20am )( tim@tim ):~/test@master✔
ls
howto la readme
#( 03/01/17@11:20am )( tim@tim ):~/test@master✔
echo "hello" >> readme && echo "hello" >> howto
#( 03/01/17@11:20am )( tim@tim ):~/test@master✗✗✗
git commit -am "edit readme and howto"
[master 8969440] edit readme and howto
2 files changed, 2 insertions(+)
所以现在我们有以下提交:
commit 8969440d52e578113f609d948e6ffd06cec96fa9
Author: Tim Richardson <[email protected] /cdn-cgi/l/email-protection>
Date: Wed Mar 1 11:20:54 2017 +0000
edit readme and howto
commit 4680089c7c1a0ead84f6b2973fd6d9e1356fd5c0
Author: Tim Richardson <[email protected] /cdn-cgi/l/email-protection>
Date: Wed Mar 1 11:20:06 2017 +0000
add la
commit fd46c4cf593752ec8163d8db21042c8dd336f529
Author: Tim Richardson <[email protected] /cdn-cgi/l/email-protection>
Date: Wed Mar 1 11:18:09 2017 +0000
howto
commit 1b7f299c5ad4fc50ce4913ab4cdbbdc761db0487
Author: Tim Richardson <[email protected] /cdn-cgi/l/email-protection>
Date: Wed Mar 1 11:17:50 2017 +0000
readme
让我们签出一个名为 test 的新分支并将其重置为初始提交:
#( 03/01/17@11:26am )( tim@tim ):~/test@master✔
git checkout -b test
Switched to a new branch 'test'
#( 03/01/17@11:27am )( tim@tim ):~/test@test✔
git reset --hard 1b7f299c5ad4fc50ce4913ab4cdbbdc761db0487
HEAD is now at 1b7f299 readme
如果我选择提交 8969440 它会失败,因为它依赖于 fd46c4c 和 1b7f29 而不是 4680089:
#( 03/01/17@11:27am )( tim@tim ):~/test@test✔
git cherry-pick 8969440
error: could not apply 8969440... edit readme and howto
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
然而,我可以从 1b7f299c 中挑选 4680089c7,而不会发生任何冲突,即使它不是 git 日志上的一级后代:
#( 03/01/17@11:28am )( tim@tim ):~/test@test✗✗✗
git reset --hard
HEAD is now at 1b7f299 readme
#( 03/01/17@12:10pm )( tim@tim ):~/test@test✔
git cherry-pick 4680089c7
[test de3878f] add la
Date: Wed Mar 1 11:20:06 2017 +0000
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 la
因此补丁之间存在一个依赖关系图,如下所示:
+---------+
| |
| 1b7f299 +--------+
| | |
+---------+ | +----------+
+----->+ |
| | 8969440 |
+---------+ | | |
| | | +----------+
| fd46c4c +--------+
| |
+---------+
+---------+
| |
| 4680089 |
| |
+---------+
我的问题是给定一个更大的存储库,如何根据补丁计算依赖关系图?我如何使用 git 来判断哪些提交依赖于其他提交?