在我的git存储库中,我有一个提交将一个分支合并到master中。但是,在合并之前,该分支上的唯一提交已添加到master,因此合并没有任何更改。合并后现在还有其他一些提交。
我想删除合并以使网络图更清洁。
网络图表:
- @a ---- @b ---- @merge --- .... more commits
| |
\------ @b ---- /
其中@a
是创建分支的位置,@b
是包含内容的提交,而@merge
没有更改
期望的状态是:
- @a ---- @b ---- ... more commits
命令git log --graph --oneline --all
给出:
* 1b1076a Add while statement
* 3d7ae6a add logical shortcircuit operators
* 96d0631 add if statement
* a56529e tidy up, add context free grammar file
* 0ba080a add javadoc comments to whole project - yay!
* 5a376b1 Add scoped variables and error when reading uninitialised variable
* a52e685 Merge branch 'master' of https://github.com/SparkleCode/Java-Interpreter
|\
| * 6cb6c07 globl variables!
* | 9a1c395 global variables
|/
* 5e5913f fixed netbeans
* 5aecfa8 initialize from old repo
* 8b30840 Initial commit
在这个日志中6cb6c07提交了与9a1c395相同的代码,使得6cb6c07和a52e685都不用了
答案 0 :(得分:1)
所以,你需要做的是改变,但请在运行任何命令之前阅读我的答案直至结束。在git中重新定位是..更改提交的基础 - 这是一种用于日常工作的典型操作。但有时 - 就像在这种情况下 - rebase可能会导致重写git的历史记录,因此更改提交ID。这可能导致需要使用-f
或--force-with-lease
开关将更改推送到远程仓库。现在,如果你在一个项目中独自工作,这应该不是问题。但是在一个团队中,它会导致远程仓库状态不连贯,如果他们不够谨慎,其他用户可能会失去工作。
那就是说,目前的状态是:
* 1b1076a 2017-11-14 18:22:46 +0000 ScratchOs (HEAD -> master, origin/master, origin/HEAD) Add while statement
* 3d7ae6a 2017-11-12 17:38:26 +0000 ScratchOs add logical shortcircuit operators
* 96d0631 2017-11-12 14:01:27 +0000 ScratchOs add if statement
* a56529e 2017-11-12 13:42:05 +0000 ScratchOs tidy up, add context free grammar file
* 0ba080a 2017-11-12 12:47:24 +0000 ScratchOs add javadoc comments to whole project - yay!
* 5a376b1 2017-11-09 20:11:48 +0000 ScratchOs Add scoped variables and error when reading uninitialised variable
* a52e685 2017-11-08 20:47:52 +0000 ScratchOs Merge branch 'master' of https://github.com/SparkleCode/Java-Interpreter
|\
| * 6cb6c07 2017-11-08 20:45:12 +0000 ScratchOs globl variables!
* | 9a1c395 2017-11-08 20:45:12 +0000 ScratchOs global variables
|/
* 5e5913f 2017-11-08 20:02:43 +0000 ScratchOs fixed netbeans
* 5aecfa8 2017-11-08 16:40:17 +0000 ScratchOs initialize from old repo
* 8b30840 2017-11-08 16:31:54 +0000 William Moreton Initial commit
您需要重新绑定 - 更改提交a52e685
的父级,因此您需要运行:
git rebase 9a1c395
结果是:
/tmp/Java-Interpreter/ [master] git rebase 9a1c395
First, rewinding head to replay your work on top of it...
Applying: globl variables!
Using index info to reconstruct a base tree...
M src/sparklecode/AstPrinter.java
M src/sparklecode/Expr.java
M src/sparklecode/Interpreter.java
M src/sparklecode/Parser.java
M src/tool/generateAst.java
Falling back to patching base and 3-way merge...
No changes -- Patch already applied.
Applying: Add scoped variables and error when reading uninitialised variable
Applying: add javadoc comments to whole project - yay!
Applying: tidy up, add context free grammar file
Applying: add if statement
Applying: add logical shortcircuit operators
Applying: Add while statement
新州是:
* b909b74 2017-11-14 18:22:46 +0000 ScratchOs (HEAD -> master) Add while statement
* 53b9e9b 2017-11-12 17:38:26 +0000 ScratchOs add logical shortcircuit operators
* 9df0bd6 2017-11-12 14:01:27 +0000 ScratchOs add if statement
* 4795c73 2017-11-12 13:42:05 +0000 ScratchOs tidy up, add context free grammar file
* 43d4cdf 2017-11-12 12:47:24 +0000 ScratchOs add javadoc comments to whole project - yay!
* 8323a42 2017-11-09 20:11:48 +0000 ScratchOs Add scoped variables and error when reading uninitialised variable
| * 1b1076a 2017-11-14 18:22:46 +0000 ScratchOs (origin/master, origin/HEAD) Add while statement
| * 3d7ae6a 2017-11-12 17:38:26 +0000 ScratchOs add logical shortcircuit operators
| * 96d0631 2017-11-12 14:01:27 +0000 ScratchOs add if statement
| * a56529e 2017-11-12 13:42:05 +0000 ScratchOs tidy up, add context free grammar file
| * 0ba080a 2017-11-12 12:47:24 +0000 ScratchOs add javadoc comments to whole project - yay!
| * 5a376b1 2017-11-09 20:11:48 +0000 ScratchOs Add scoped variables and error when reading uninitialised variable
| * a52e685 2017-11-08 20:47:52 +0000 ScratchOs Merge branch 'master' of https://github.com/SparkleCode/Java-Interpreter
| |\
|/ /
| * 6cb6c07 2017-11-08 20:45:12 +0000 ScratchOs globl variables!
* | 9a1c395 2017-11-08 20:45:12 +0000 ScratchOs global variables
|/
* 5e5913f 2017-11-08 20:02:43 +0000 ScratchOs fixed netbeans
* 5aecfa8 2017-11-08 16:40:17 +0000 ScratchOs initialize from old repo
* 8b30840 2017-11-08 16:31:54 +0000 William Moreton Initial commit
请注意,上面的提交9a1c395
哈希值已更改,并且存储库HEAD -> master
与(origin/master, origin/HEAD)
的状态不一致。现在你需要推动改变:
git push --force-with-lease