意想不到的 "git rebase" 效果?

Unexpected "git rebase" effect?

git log结果rebase:

$ git log --branches --graph --oneline                                                 
* ea450cb (HEAD -> v1.0) combination lots of modifies..
* d602e25 nnew edit
| * 51bfb5f (master) abc added
|/  
* 11e16ef animals gg
* 78e1630 (origin/master, origin/HEAD, brc) important backup file is forced to commit.
* 7a87267 nc.txt is ignored, anymore.
* 5def0f6 (tag: v2.0) local .ignre and test *.dat files.
* 1591c3a ignoreDir directory *.dat files are ignored.
* f84ad0d log add
* ac462c0 .gitignore test.
* 4d1e437 .gitignore file is added
* b3574db hüloo
*   3389e5c merge2
|\  
| * bb64902 (origin/confl) Change line.
| * 14f7040 İnit for another conflict exercise.
* | ca51aef (tag: v1.0) Truth of line.
* | f4fcc04 Init for another conflict exercise.
|/  
*   0f251b2 Merge branch 'octodog'

我想改变它(只关注 最后 3 次提交):

$ git log --branches --graph --oneline                                                 
* 51bfb5f (master) abc added
* ea450cb (HEAD -> v1.0) combination lots of modifies..
* d602e25 nnew edit
* 11e16ef animals gg
* 78e1630 (origin/master, origin/HEAD, brc) important backup file is forced to commit.
* 7a87267 nc.txt is ignored, anymore.
* 5def0f6 (tag: v2.0) local .ignre and test *.dat files.
* 1591c3a ignoreDir directory *.dat files are ignored.
* f84ad0d log add
* ac462c0 .gitignore test.
* 4d1e437 .gitignore file is added
* b3574db hüloo
*   3389e5c merge2
|\  
| * bb64902 (origin/confl) Change line.
| * 14f7040 İnit for another conflict exercise.
* | ca51aef (tag: v1.0) Truth of line.
* | f4fcc04 Init for another conflict exercise.
|/  
*   0f251b2 Merge branch 'octodog'

但是当我完成后:

$ git checkout master
$ git rebase v1.0

变成了:

$ git log --branches --graph --oneline                                                 
* 8c4a1e6 (HEAD -> master) abc added
* 22b75db animals gg
* 6f88917 important backup file is forced to commit.
* 69ef5c8 nc.txt is ignored, anymore.
* 36a270d local .ignre and test *.dat files.
* 55e7afd ignoreDir directory *.dat files are ignored.
* aac484c log add
* 5d13b95 .gitignore test.
* 51cf1e9 .gitignore file is added
* d1d37cd hüloo
| * ea450cb (v1.0) combination lots of modifies..
| * d602e25 nnew edit
| * 11e16ef animals gg
| * 78e1630 (origin/master, origin/HEAD, brc) important backup file is forced to commit.
| * 7a87267 nc.txt is ignored, anymore.
| * 5def0f6 (tag: v2.0) local .ignre and test *.dat files.
| * 1591c3a ignoreDir directory *.dat files are ignored.
| * f84ad0d log add
| * ac462c0 .gitignore test.
| * 4d1e437 .gitignore file is added
| * b3574db hüloo
| *   3389e5c merge2
| |\  
|/ /  
| * bb64902 (origin/confl) Change line.
| * 14f7040 İnit for another conflict exercise.
* | ca51aef (tag: v1.0) Truth of line.
* | f4fcc04 Init for another conflict exercise.
|/  
*   0f251b2 Merge branch 'octodog'

如您所见,从 3389e5c merge211e16ef animals gg ,它应用了两次提交。

为什么它没有像我预期的那样工作?我的目标是什么?

你有 两个 东西叫做 v1.0.

一个是你的当前分支:

* ea450cb (HEAD -> v1.0) combination lots of modifies..

另一个是标签:

* | ca51aef (tag: v1.0) Truth of line.

当您询问 Git 关于 v1.0 时,它会 通常 选择标签,在这种情况下意味着提交 ca51aefgit rebase.

就是这种情况

git checkout 命令将改为选择分支。)

要使您希望发生的事情真正发生,您有多种选择:

  • 通过哈希 ID 命名提交:git rebase ea450cb
  • 用 more-complete 名称命名提交:git rebase heads/v1.0git rebase refs/heads/v1.0
  • 通过重命名分支来解决根本问题:v1.0 不是一个好的分支名称,而是一个好的标签名称,所以保留标签,并更改分支名称。