【问题标题】:git rebase HEAD^^ failsgit rebase HEAD^^ 失败
【发布时间】:2019-09-24 13:22:43
【问题描述】:

这让我很困惑:通常git rebase HEAD^^^^^^^ 只是说:

当前分支测试是最新的。

然而,今天,我向同事演示 git rebase -i,我首先做了 git rebase 63c1e126,其中 63c1e126 是从提交日志中挑选的提交,并且 rebase 因冲突而失败。怎么会这样?

执行 rebase -i 的原因是为了清理一个问题,即在其他 rebase/force push 混乱(我猜)之后,相同的提交被应用了两次,并且 rebase 在第一次提交时发生冲突第二次申请(使用不同的提交哈希和一些空白更改)。

git 的输出:

$ git rebase 63c1e126
First, rewinding head to replay your work on top of it...
Applying: Cherrypicking python files to commit to master
Applying: (#1379) Included .nc files in ignore-list
Applying: Added monthly index-file and stations rtf to gitignore
Applying: Initial clean-up
Applying: Reformat using Eclipse formatting rules
Applying: (#1386) Remove panelGrid warning on login page
...
Applying: (#1378) Apply replacement column headers on export
Applying: (#1378) Eclipse formatting
Applying: (#1381) facilitating new object_spec
Applying: Initial clean-up
Using index info to reconstruct a base tree...
M   WebApp/WebContent/resources/python/export/py_func/copernicus.py
.git/rebase-apply/patch:33: trailing whitespace.
      #local_folder = filepath_local.rsplit('/',1)[0] 
warning: 1 line adds whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging WebApp/WebContent/resources/python/export/py_func/copernicus.py
CONFLICT (content): Merge conflict in WebApp/WebContent/resources/python/export/py_func/copernicus.py
error: Failed to merge in the changes.
Patch failed at 0022 Initial clean-up
Use 'git am --show-current-patch' to see the failed patch

Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".

git log 给出类似(替换的提交哈希):

$ git log --graph --decorate --oneline
* aaaaaaaa (HEAD -> github/1381_bak, origin/github/1381_bak) (# 1381) index file added to gitignore
* aaaaaaaa (#1381) Clean up
* aaaaaaaa (#1381) Added delete folder functionality
* aaaaaaaa (#1381) Added export-date to CMEMS export database
* aaaaaaaa (#1381) Working CMEMS version
* aaaaaaaa (#1381) Making local_folder global variable, and minor bug-fixes
* aaaaaaaa (#1381) General cleanup
* aaaaaaaa (#1381)  Removing stray debugging
* aaaaaaaa (#1381) Removing bad use of try:except statements
* aaaaaaaa (#1381) General clean-up and improved SQL-functionality
* aaaaaaaa (#1381) Facilitating change in directory structure
*   aaaaaaaa Merge remote-tracking branch 'origin/github/1381' into github/1381
|\  
| * aaaaaaaa (#1381) facilitating new object_spec
| * aaaaaaaa (#1381) Improved handling of L0 files
| * aaaaaaaa (#1381) toml files included in setup-scripts
| *   aaaaaaaa Merge branch 'github/1381' into origin/github/1381
| |\  
| | * aaaaaaaa (#1381) Fixed bug in sql-db
| | * aaaaaaaa (#1381) Updated .gitignore file
| | * aaaaaaaa (#1381) Minor function renaming. just aesthetic.
| | * aaaaaaaa (#1381) get_export_list:  bug-fix
| | * aaaaaaaa (#1381) Putting cmems_delay function on hold.
| | * aaaaaaaa (#1381) Reworked logic to omit use of sys.exit()
| |/  
| * aaaaaaaa (#1381) Style and format cleanup for readability
| * aaaaaaaa (#1381) meta handling clean-up
| * aaaaaaaa Initial clean-up
* | aaaaaaaa (#1381) facilitating new object_spec
* | aaaaaaaa (#1381) Improved handling of L0 files
* | aaaaaaaa (#1381) toml files included in setup-scripts
* | aaaaaaaa (#1381) Fixed bug in sql-db
* | aaaaaaaa (#1381) Updated .gitignore file
* | aaaaaaaa (#1381) Minor function renaming. just aesthetic.
* | aaaaaaaa (#1381) get_export_list:  bug-fix
* | aaaaaaaa (#1381) Putting cmems_delay function on hold.
* | aaaaaaaa (#1381) Reworked logic to omit use of sys.exit()
* | aaaaaaaa (#1381) Style and format cleanup for readability
* | aaaaaaaa (#1381) meta handling clean-up
* | aaaaaaaa Initial clean-up
* | aaaaaaaa (origin/v2.0.6a) (#1378) Eclipse formatting
* | aaaaaaaa (#1378) Apply replacement column headers on export
* | aaaaaaaa (#1378) Don't include units if replacement column headers are configured
* | aaaaaaaa (#1378) Add replaceColumnHeaders to export config
* | aaaaaaaa (#1386) Remove panelGrid warning on login page
* | aaaaaaaa Reformat using Eclipse formatting rules
|/  
* aaaaaaaa (origin/master, origin/HEAD, master) Added monthly index-file and stations rtf to gitignore
* aaaaaaaa (#1379) Included .nc files in ignore-list
* aaaaaaaa Cherrypicking python files to commit to master
* 63c1e126 (#1331) integration with new cmems_converter.py

【问题讨论】:

  • 你认为 rebase 是一个无冲突的操作吗?变基时的冲突不会系统地发生,它们取决于更改的性质,但它们确实可能发生。变基基本上是一种自动化一系列精选(提交的复制)的方法
  • 是的,我想我希望它们在基于我自己分支上的先前提交时不会发生冲突
  • 很公平,你是对的,我有点想念你选择的哈希来自同一分支的历史。
  • 你能提供你的 git log 和 git status 输出吗?
  • 只是看着它,我觉得它开始有点意思了:) 我会在这里添加它

标签: git rebase


【解决方案1】:

git log 对您撒谎并显示线性历史。 Git 历史不是线性的,分支和合并就是这样。 git log --graph 显示了真实的历史。你的历史已经融入其中。这意味着您的提交历史看起来像这样。

63c1e126 - B - C - I - G - H - K [github/1381_bak]
            \         /
             D - E - F

git rebase,默认情况下,会丢弃合并提交并展平您的历史记录。像这样。

63c1e126 - B - D1 - C1 - E1 - I1 - F1 - G1 - H1 - K1 [github/1381_bak]

注意现在分支的提交是如何交错的。这可能会导致冲突,因为 E 没有写在 C 之上。

如果我们查看 rebase 排序,我们可以在 Added monthly index-file and stations rtf to gitignore 之后看到交错提交。 Initial clean-upReformat using Eclipse formatting rules 最初都写在 Added monthly index-file and stations rtf to gitignore 之上。但是 rebase 是将Reformat using Eclipse formatting rules 放在Initial clean-up 之上。第二个Initial clean-up也有类似问题。

$ git rebase 63c1e126
First, rewinding head to replay your work on top of it...
Applying: Cherrypicking python files to commit to master
Applying: (#1379) Included .nc files in ignore-list
Applying: Added monthly index-file and stations rtf to gitignore
Applying: Initial clean-up                                        (right)
Applying: Reformat using Eclipse formatting rules                 (left)
Applying: (#1386) Remove panelGrid warning on login page          (left)
...
Applying: (#1378) Apply replacement column headers on export
Applying: (#1378) Eclipse formatting
Applying: (#1381) facilitating new object_spec
Applying: Initial clean-up

请注意,如果您使用相当新的 git rebase -r--rebase-merges,Git 将尝试保留您的分支并重新创建合并。除非您明确想要展平您的历史记录,否则请使用 -r

【讨论】:

  • 很好,谢谢。对于我自己的项目,我一般在合并之前rebase在master上,所以我得到了这个超级平滑的线性历史。不过,重新考虑该策略,rebase -r 听起来像是一条路。
  • @jonasfh 我也这样做,与git pull --rebase 并与git merge --no-ff 合并以形成像您这样的简洁功能气泡。我推荐这个策略。 git rebase -r 在重写复杂历史时很有用。
猜你喜欢
  • 2016-04-14
  • 2010-11-05
  • 2014-10-29
  • 2014-06-06
  • 1970-01-01
  • 2021-10-28
  • 1970-01-01
  • 2022-06-24
  • 2021-08-18
相关资源
最近更新 更多