【发布时间】:2019-12-15 17:47:15
【问题描述】:
绝对是 git 的新手,因此这里可能是一个非常愚蠢的问题:
我有一个 master 分支,我开始在其中进行增强。 大约 20 次提交后,我意识到我应该创建一个单独的分支并完成我的工作。
所以我从 master 创建了一个新的 main/dev 分支,然后我将 master 分支指针重置为指向初始 repo 提交,这是我开始工作之前的点:
$ git reset --hard <commit hash>
在我这样做之后,我立即想到了以下工作流程(不确定从哪里来--lol):
我的想法是沿着我自己的“主”分支而不是在 master 上进行所有主要开发。然后我会从这个主分支创建新的功能/增强分支,我猜是开发分支?然后我最终会将新的增强工作重新合并到“主”分支中,然后当我自己的所有“主”工作完成后将其合并到主分支中(不确定这是否是一个好的工作流程......似乎不是所以)。
因此,在这个好主意之后,我立即想到“嗯……让我从 main 中创建另一个单独的特定“增强”分支。
我想我可能错误地创建了“子”增强分支。 在“主要”上,我刚刚使用了
$ git checkout -b enhancement
不是
$ git checkout -b enhancement main
现在当我在“main”分支上运行时:
$ git merge enhancement
我得到以下信息:
Already up to date.
当我跑步时
$ git show-branch
据我了解,它用于显示所有分支及其所有提交,我得到以下输出:
! [enhancement] Test enhancing, fixing, and cleaning.
* [main] Test enhancing, fixing, and cleaning.
! [master] Grammar improvements
---
+* [enhancement] Test enhancing, fixing, and cleaning.
+* [enhancement^] Bug Fix: addition of path id to updateTodo method.
+* [enhancement~2] Additon of tests to TodoTest.java and TodoResourceTest.java for ValidForUpdate Todo annotation.
+* [enhancement~3] Refactoring: moved all custom validation messages to properties file and all associated changes. Also cleaned up imports here and there.
+* [enhancement~4] Refactoring: moved PastOrPresentValidator to an inner class of the PresentOrPast annotation class.
+* [enhancement~5] Addition of ValidForUpdate custom constraint Todo object annotation and freinds.
+* [enhancement~6] Fixed problem of same four tests failing when run with all tests in class but passing individually. Changed init from 'BeforeClass' to 'BeforeEach' fixed it.
+* [enhancement~7] Added properties to enable forked & threaded test processing in surefire plugin.
+* [enhancement~8] Added propertey for maven surefire plugin version.
+* [enhancement~9] Refactoring of tests. Move of mian Todo template test object and friends to central location of TestTodoCreater.
+* [enhancement~10] Refactoring to get PresetntOrPast validation error message from properties file. Also some slight refactoring by replacing validation error message string literals in tests with string constant.
+* [enhancement~11] Addition of new 'PresentOrPast' validator and accompanying test changes. Also a little bit of test clean-up/refactoring.
+* [enhancement~12] Addition of 'updateTodo' api method and accompanying tests. Tightening up of validation annotations in TodoResource. Addition of Todo field validations and all accompanying tests. Major refactoring of TodoResourceTest.
+* [enhancement~13] Backed out previous commit's changes and updated dropwizard version to 1.3.13. Changes backed out due to what appears to be lack of Hibernate Validator 6 support in the dropwizard-testing library.
+* [enhancement~14] Moved ValidationMessages.properties file. Still not yet using.
+* [enhancement~15] updated hibernate-validator and java validation-api to latest versions.
+* [enhancement~16] Changes required to add 'update' method to TodoDAO and some code cleanup.
+* [enhancement~17] Changes in order to get maven to run ALL (Junit5) tests with 'mvn test'. Specific changes to get TodoIntegrationSmokeTest to run by adding test-config.yml.
+* [enhancement~18] Completion of TodoIntegratoinSmokeTest for pre-existing api methods.
+* [enhancement~19] Initial commit of TodoIntegratoinTest with working testCreateTodo method.
+* [enhancement~20] Some minor code cleanup up and refactoring.
+* [enhancement~21] completed tests for pre-existing api methods.
+* [enhancement~22] Cleaned up TodoResource test and TestUtils.
+* [enhancement~23] All API methods test-covered 'except' for deleteTodo.
+* [enhancement~24] Validation for TododResource#getTodos and accompanying test changes .
+* [enhancement~25] Began shoring-up code with parameter validation and accompanying test changes.
+* [enhancement~26] Completed bulk of TodoDaoTest but missing update implementation and some odds and ends.
+* [enhancement~27] A little more clean up/refactoring of TodoDAO associated test classes.
+* [enhancement~28] Clean up of TodoDAOTest2
+* [enhancement~29] Slight modification to server rootPath value.
+* [enhancement~30] Addition of beginning of Todo DAO test classes. Creates a PostgresSQL Docker container and laods the schema with flyway.
+* [enhancement~31] Replaced TodoResource string literal test path values with static UriBuilders.
+* [enhancement~32] Changes in this commit are in support of getting the TodoResourceTest completed by covering all original api methods(given with task).
+* [enhancement~33] Small change. Renamed Todo JSON test class to 'TodoRepresentationTest' to use Dropwizard-specific terminology. Removed non-used import.
+* [enhancement~34] Conversion of Todo class into an immutable 'value' class. Added tests for serializing and deserializing Todo objects to and from JSON.
+*+ [master] Grammar improvements
除非我误解了该命令的输出,否则“main”似乎包含与“enhancement”相同的所有提交,这使得我对增强分支所做的任何提交看起来也以某种方式被提交到主分支。
看起来我一直在工作并同时向两个分支提交相同的内容。
运行后也是
git show-ref --head
我明白了:
b43e3c2b3d19a4a19497cf78e3909727f25796a2 HEAD
b43e3c2b3d19a4a19497cf78e3909727f25796a2 refs/heads/enhancement
b43e3c2b3d19a4a19497cf78e3909727f25796a2 refs/heads/main
...
这表明 HEAD 同时指向两个分支? 这是怎么发生的???
当我运行命令以显示两个分支之间的不同提交时:
$ git log --left-right --graph --cherry-pick --oneline main...enhancement
没有输出。 所以这就是说这两个分支之间根本没有区别。 所以我真的很想知道我在这里做了什么。
我喜欢 git,但她又让我感到困惑 :(.
我已经阅读了 git 中的“分支”,据我所知,分支只是指向特定提交的指针,而 HEAD 指向的任何分支都是您当前工作的分支,因此在提交时将只需在 HEAD 顶部添加连续提交,同时将 HEAD 推进到该分支中的最新提交。
所以我的增强分支的 HEAD 应该在包含提交 main 的主分支的 HEAD 之前。
我不明白的是,如果我在过去 17 次提交中一直在增强分支中工作,那么当我切换到任一分支时,HEAD 为何会指向同一个提交。
所以我期望看到的是不同的提交历史,增强包含更多的提交,但我没有,他们有相同的提交!
请有人怜悯并通过向我指出我在这里做错了什么来提供一些启发。我一直在努力解决这个问题。
任何和所有的帮助都无法估量!
【问题讨论】:
-
只是对我的情况的跟进:在阅读了@torek 最慷慨的信息回复后,我决定在“主”分支上做一个
git reset --hard master,一个基于“增强”分支来清理提交历史,然后,在找到一篇关于 rebase here 的好文章后,决定在“main”上使用“enhancement”执行“rebase-and-merge”工作流程。非常非常感谢@torek 的贡献。希望这也能帮助许多其他人。干杯! -卢克
标签: git branch branching-strategy