场景:
问题:如何才能取回我删除和解锁的分支,使主服务器在没有特性分支(蓝色)的情况下看起来很干净?我将来可能还需要为该特性处添加提交。
我是否需要同时完成上述两项工作才能得到预期的结果?还是我想要创建一个新的分支并还原添加在功能分支中的提交并合并它?
我完全迷茫了,请把我重新引导到正确的道路上。下面给出了用例的示例Git图。
注意:在特性分支(蓝色)之间没有合并。
var gitgraph = new GitGraph({
template: "metro", // or blackarrow
orientation: "horizontal",
author: "John Doe",
mode: "compact" // or compact if you don't want the messages
});
const master = gitgraph.branch("master");
master.commit("Init the project");
master.commit("Master Commit");
master.tag("v1.0");
const newFeature = gitgraph.branch("feature-1");
newFeature.commit("Feature#1 Commit-1");
master.commit("Hotfix Bug1");
const development = master.branch("development");
development.commit("Development Commit-1");
development.commit("Development Commit-2");
master.commit("HotFix Bug2");
const anotherFeature = master.branch("feature-2");
anotherFeature.commit("Feature#2 Commit-1");
anotherFeature.commit("Feature#2 Commit-2");
newFeature.commit("Feature#1 Commit-2");
newFeature.commit("Feature#1 Commit-3");
master.commit("HotFix Bug3");
master.commit("HotFix Bug4");
newFeature.merge(master, "Release Feature#1");
master.tag("v2.0");
master.commit("Additional Commit-1");
development.merge(master, "Development Merge");
master.commit("Additional Commit-2");
master.tag("HEAD");<script src="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Git Graph</title>
</head>
<body>
<canvas id="gitGraph"></canvas>
</body>
</html>

发布于 2020-05-24 08:24:21
您可以使用git revert --mainline 1 <commit-id>撤消合并提交,其中<commit-id>用于从上面的图片中表示Release Feature#1。--mainline 1是合并提交恢复所必需的,并指示应该将合并的哪一边还原到它的第一个父级,因为通常将特性分支合并到主服务器中。
您还可以将已删除的特性分支还原为一个分支,从合并之前开始,遵循第二个父git branch feature-1 <commit-id>^2 (与上面相同的提交id)。
但是,由于分支已经合并,以后将无法再次合并它。最简单的方法是重新建立分支的基础,这将在最新的主服务器顶部创建特性分支提交的副本。
git checkout feature-1
git rebase master
...resolve conflicts, do more amendments, etc
git checkout master
git merge feature-1发布于 2020-05-24 06:22:13
只需撤销所有提交主分支上的,直到您回到合并提交(与已删除的分支)。
因为合并两个线程也是一个提交,那么您就可以撤销它。
备注:您还可以使用git rebase (这里有更多关于这个的事情)将您所做的单个提交移动到另一个分支,如果需要的话
参考资料:
https://stackoverflow.com/questions/61982274
复制相似问题