Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 希望将更改从分支合并到分支,但两者都包含相同的提交_Git_Branch_Branching Strategy - Fatal编程技术网

Git 希望将更改从分支合并到分支,但两者都包含相同的提交

Git 希望将更改从分支合并到分支,但两者都包含相同的提交,git,branch,branching-strategy,Git,Branch,Branching Strategy,对于git来说,这绝对是一个新手,因此下面的问题可能是一个非常愚蠢的问题: 我有一个主分支,我开始在其中进行增强。 大约二十岁左右,我意识到我本应该单独做一个分支,在上面完成我的工作 因此,我在master上创建了一个新的main/dev分支,然后将master分支指针重置为指向初始repo commit的点,这是我开始工作之前的点: $ git reset --hard <commit hash> 不是 现在,当我在“主”分支上运行时: 我得到以下信息: Already up t

对于git来说,这绝对是一个新手,因此下面的问题可能是一个非常愚蠢的问题:

我有一个主分支,我开始在其中进行增强。 大约二十岁左右,我意识到我本应该单独做一个分支,在上面完成我的工作

因此,我在master上创建了一个新的main/dev分支,然后将master分支指针重置为指向初始repo commit的点,这是我开始工作之前的点:

$ git reset --hard <commit hash>
不是

现在,当我在“主”分支上运行时:

我得到以下信息:

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
...
这表示头部同时指向两个分支? 这是怎么发生的

此外,当我运行命令以显示两个分支之间的不同提交时:

$ git log --left-right --graph --cherry-pick --oneline main...enhancement

没有输出。 这意味着这两个分支之间根本没有区别。 所以我真的对我在这里做的事感到抓狂

我爱git,但她又让我感到困惑:(

我已经阅读了git中的“分支”,从中我可以看出,分支只是指向特定提交的指针,任何分支头指向的都是您当前正在使用的分支,因此提交后,只需在头上添加连续的提交,同时将头推进到该分支中最近的提交

因此,我的增强分支的负责人应该远远领先于我的主要分支的负责人

我不明白的是,如果我在增强分支中工作了17次提交,那么当我切换到任何一个分支时,头部为什么指向同一个提交

所以我希望看到的是不同的提交历史,增强包含更多的提交,但我没有,它们有相同的提交

求你了,有人发发发慈悲,给我点启示,告诉我我做错了什么。我在这上面撞了很久了


感谢所有的帮助!

您的问题的根源在于分支不分等级

提交有一个图形结构。特别是,几乎每个提交都有一个父级,有些提交有两个父级。有些奇怪的提交可能有三个或更多,并且至少有一个在存储库中进行的第一次提交必然没有父级

正是这种父/子关系形成了图形结构。我们可以从一个很小的存储库开始,只进行三次提交:

A <-B <-C
但是分支名称从何而来呢?记住,每个提交都有一些大而难看的随机散列ID。以下是四个实际的散列ID,按顺序排列:

7c20df84bd21ec0215358381844274fa10515017
14fe4af084071803ab4f16e6841ff64ba7351071
c62bc49139f1d18e922fc98e35bb08b1aadbcafc
9b274e28871b3e4a4109582a34625df5fddc91c8
我应该称之为提交
A
,我应该称之为提交
B
,依此类推?如果我想像Git一样在最新提交的末尾开始,我是从
14fe…
开始,还是从
9b27…
开始,或者是什么

我们可以查看这四个提交中的每一个,以查看它们存储的父哈希ID。例如:

$ git cat-file -p 9b274e28871b3e4a4109582a34625df5fddc91c8 | sed 's/@/ /'
tree c921299d1381a3bd6486ef999e3cc432118d1d72
parent e46249f73ebddca06cf16c01e8de1f310360c856
parent f3eda90ffc10f9152e7492a34408a9f5e4c28b0f
author Junio C Hamano <gitster pobox.com> 1564776722 -0700
committer Junio C Hamano <gitster pobox.com> 1564776722 -0700

Merge branch 'jc/log-mailmap-flip-defaults'

Hotfix for making "git log" use the mailmap by default.

* jc/log-mailmap-flip-defaults:
  log: really flip the --mailmap default
  log: flip the --mailmap default unconditionally

AHA,这是我上面列出的四个提交之一!提交是Git应该考虑的最后一个提交,它是<代码>主代码>代码>。如果我们在里面查看:

$ git cat-file -p 7c20df84bd21ec0215358381844274fa10515017 | sed 's/@/ /'
tree 8858576e734aa4f1cd9b45e207e7ee2937488d13
parent 14fe4af084071803ab4f16e6841ff64ba7351071
author Junio C Hamano <gitster pobox.com> 1564776744 -0700
committer Junio C Hamano <gitster pobox.com> 1564776744 -0700

Git 2.23-rc1

Signed-off-by: Junio C Hamano <gitster pobox.com>
H
7c20…
提交,而
G
14fe…
提交。让我们看看
G
的父级,这次使用
git rev parse
及其特殊的“打印所有父级哈希ID”语法:

c62b…
一个是我的四个列表中的第三个;还有一个不在我的列表中。这个提交是一个合并提交,如果我们查看它的其余部分,可以看到:

$ git cat-file -p 14fe4af084071803ab4f16e6841ff64ba7351071 | sed 's/@/ /'
tree 06a0b1de4cb3857cdd23a939a857dc720240496b
parent c62bc49139f1d18e922fc98e35bb08b1aadbcafc
parent d61e6ce1dda7f4b11601a0de549feefbcec55779
author Junio C Hamano <gitster pobox.com> 1564776723 -0700
committer Junio C Hamano <gitster pobox.com> 1564776723 -0700

Merge branch 'sg/fsck-config-in-doc'

Doc update.

* sg/fsck-config-in-doc:
  Documentation/git-fsck.txt: include fsck.* config variables
现在让我们输入分支名称
master
。名称本身标识提交
H
,并且仅直接表示提交
H
,因此:

...--F--G--H   <-- master
       /
 ...--I
让我们也画上这个名字,指向commit
I

...--F--G--H
       /
 ...--I
...--F--G--H   <-- master
       /
 ...--I   <-- sg/fsck-config-in-doc
并要求Git创建一个新名称
主题
,我们得到:

...--F--G--H   <-- master, topic
       /
 ...--I   <-- sg/fsck-config-in-doc
当我们进行新的提交时,它的父项将是
H
topic
前面的提示,新的提交将成为名称
topic
标识的提交:

             J   <-- topic (HEAD)
            /
...--F--G--H   <-- master
       /
 ...--I   <-- sg/fsck-config-in-doc
提交
J
仍然存在,但现在将很难找到。如果你从
master
开始向后工作,你会得到
H
,然后是
G
,然后是
F
I
,依此类推。你无法到达
J
:箭头指向错误的方向。如果你从
主题的顶端开始,它会是什么现在是
I
,并且向后工作,您无法到达
J
。提交
J
实际上已被放弃

特定命令使用这些名称执行特定操作 正如您已经看到的,
git checkout-b

  • 创建一个新的分支名称,指向一些现有的提交,然后
  • 对新名称执行
    git签出
    ,以便
    HEAD
    附加到该名称,并且现有提交将成为当前提交
同时,
git重置——硬的

  • 获取一个可选名称或哈希ID,或者任何
    git rev parse
    可以处理的内容,并将其转换为哈希ID,然后

  • 获取附加到
    头的当前分支名称,并使其指向该特定提交

  • 因为这个是
    --硬的
    ,所以它也是
    $ git rev-parse 14fe4af084071803ab4f16e6841ff64ba7351071^@
    c62bc49139f1d18e922fc98e35bb08b1aadbcafc
    d61e6ce1dda7f4b11601a0de549feefbcec55779
    
    $ git cat-file -p 14fe4af084071803ab4f16e6841ff64ba7351071 | sed 's/@/ /'
    tree 06a0b1de4cb3857cdd23a939a857dc720240496b
    parent c62bc49139f1d18e922fc98e35bb08b1aadbcafc
    parent d61e6ce1dda7f4b11601a0de549feefbcec55779
    author Junio C Hamano <gitster pobox.com> 1564776723 -0700
    committer Junio C Hamano <gitster pobox.com> 1564776723 -0700
    
    Merge branch 'sg/fsck-config-in-doc'
    
    Doc update.
    
    * sg/fsck-config-in-doc:
      Documentation/git-fsck.txt: include fsck.* config variables
    
    ...--F--G--H
           /
     ...--I
    
    ...--F--G--H   <-- master
           /
     ...--I
    
    git merge sg/fsck-config-in-doc
    
    ...--F--G--H   <-- master
           /
     ...--I   <-- sg/fsck-config-in-doc
    
    ...--F--G--H   <-- master
           /
     ...--I   <-- sg/fsck-config-in-doc
    
    ...--F--G--H   <-- master, topic
           /
     ...--I   <-- sg/fsck-config-in-doc
    
    ...--F--G--H   <-- master, topic (HEAD)
           /
     ...--I   <-- sg/fsck-config-in-doc
    
                 J   <-- topic (HEAD)
                /
    ...--F--G--H   <-- master
           /
     ...--I   <-- sg/fsck-config-in-doc
    
                 J
                /
    ...--F--G--H   <-- master
           /
     ...--I   <-- sg/fsck-config-in-doc, topic (HEAD)
    
    ...--F--G--H   <-- master
                \
                 I--J--...--N   <-- main (HEAD), enhancement
    
    git reset --hard master
    
    ...--F--G--H   <-- master, main (HEAD)
                \
                 I--J--...--N   <-- enhancement
    
    ...--F--G--H   <-- master
                \
                 I--J--...--N   <-- main (HEAD), enhancement
    
    ...--F--G--H   <-- master (HEAD)
    
    git checkout -b branch
    
    ...--F--G--H   <-- master, branch (HEAD)
    
    ...--F--G--H   <-- master
                \
                 I   <-- branch (HEAD)
    
    ...--F--G--H   <-- master
                \
                 I--J   <-- branch (HEAD)
    
                 I--J   <-- branch
                /
    ...--F--G--H   <-- master (HEAD)
    
                 K--L   <-- master (HEAD)
                /
    ...--F--G--H
                \
                 I--J   <-- branch
    
                 K--L
                /    \
    ...--F--G--H      M   <-- master (HEAD)
                \    /
                 I--J   <-- branch
    
    ...--F--G--H   <-- master, main (HEAD)
                \
                 I--J--...--N   <-- enhancement
    
                 ,------------------O   <-- main (HEAD)
                /                  /
    ...--F--G--H   <-- master     /
                \                /
                 I--J----...----N   <-- enhancement
    
    ...--F--G--H   <-- master
           /
     ...--I   <-- sg/fsck-config-in-doc
    
    ...--F--G--H   <-- master
           /
     ...--I
    
    ...--F--G--H   <-- master, main (HEAD)
                \
                 I--J--...--N   <-- enhancement
    
    ...--F--G--H--O--P   <-- main