问题描述
假设我们有两个 git 分支,a
和 b
(为了简单起见,假设它们都是本地的)。分支 a
是我的工作,分支 b
不是;我不能碰它。
我想将 b
的合并“声明”或“标记”到 a
,而不实际对分支 a
中的代码进行任何更改。我不介意做一个空提交来表示合并。动机是分支 b
上发生了多余的工作,因为分支 a
上的工作发生了分歧,因此它们被包含在 var graph = {
nodes: markers,links: paths
}
// GeoMercator projection,Could change depending on aesthetic requirement.
const projection = d3.geoMercator()
.scale(width/Math.PI/2) // 960 pixels over 2 π radians
.translate([width/2,height/2]);
const pathGenerator = d3.geoPath().projection(projection);
// Could cause problems,check this when debugging any issue.
const g = svg.append('g');
svg.call(d3.zoom().on('zoom',(event,d)=>{
g.attr('transform',event.transform);
}))
// Attaching the map and required markers and links to it.
var mapGroup = g.append('g');
var force = d3.forceSimulation()
.force("link",d3.forceLink()
.id(function(d){
return d.name;
}).strength(0.3))
.force("charge",d3.forceManyBody())
.force("y",d3.forceY(d =>{
console.log(d)
return d.fy;
}).strength(0.1))
.force("center",d3.forceCenter(width / 2,height / 2))
.force("x",d3.forceX(d => {
return d.fx;
}).strength(0.5))
.force("collide",d3.forceCollide().radius(d => 3 + 1).iterations(2));
d3.json('static/countries.json')
.then(data => {
const countries = topojson.feature(data,data.objects.countries);
var map = mapGroup.append('g')
.selectAll('path')
.data(countries.features)
.enter().append('path')
.attr('class','country')
.attr('d',pathGenerator);
// Create the links
var links = mapGroup.append('g')
.selectAll(".arc")
.data(graph.links)
.enter()
.append("line")
.attr('class','arc')
.attr("stroke-width",2)
.attr("stroke","black")
.on('mouSEOver',function(d,e) {
d3.select(this).style("stroke","white")
})
.on('mouSEOut',function(d) {
d3.select(this).style("stroke","grey")
})
// Draw the paths
var nodes = mapGroup.append('g')
.selectAll("circle")
.data(graph.nodes)
.enter()
.append("circle")
.attr("r",3)
.style("fill","white")
.attr("stroke","#1a243d")
.attr("stroke-width",3)
.attr("Box-sizing","border-Box")
.call(d3.drag()
.on("start",dragInitial)
.on("drag",dragging)
.on("end",dragTerminate))
.on('mouSEOver',"#1a243d")
})
force.nodes(graph.nodes);
force.force("link").links(graph.links);
graph.nodes.forEach(function(d) {
if(d.lon && d.lat) {
var p = projection([d.lon,d.lat]);
d.fx = p[0];
d.fy = p[1];
}
})
force.on("tick",function (){
links
.attr('x1',function(d){
return d.source.x;
})
.attr('y1',function(d){
return d.source.y;
})
.attr('x2',function(d){
return d.target.x;
})
.attr('y2',function(d){
return d.target.y;
});
nodes
.attr('cx',function(d){
return d.x;
})
.attr('cy',function(d){
return d.y;
})
.attr("r",function(d) {return 3; });
});
});
function dragInitial(d,e){
if (d.active == 0) force.alphaTarget(0.3).restart();
e.fx = d.x;
e.fy = d.y;
}
function dragging(d,e){
e.fx = d.x;
e.fy = d.y;
}
function dragTerminate(d,e){
if(d.active == 0) force.alphaTarget(0);
var p = projection([e.lon,e.lat]);
e.fx = p[0];
e.fy = p[1];
}
上。
假设这是一件“合法”的事情——这样做的惯用方法是什么?
解决方法
这是我现在的做法:
git br a
-
git merge --no-commit b
(如果git pull --no-commit remote-name-here b
是远程的,则为b
) - 取消添加所有内容
- 编辑提交冲突以仅保留
a
版本 -
git commit
并更改注释以说明我将标记为已合并但未采用更改。
没有惯用的方法来做到这一点,因为它不是一个常见的用例。假设您只是不想拥有未合并的分支,那么有一些变通方法可能对您有用,具体取决于您的情况:
- 删除分支
- 合并分支,然后还原合并提交(然后合并,但更改不存在)
- 恢复分支上的所有提交,然后合并它。
我认为它可以像这样轻松制作:
git commit-tree -p a -p b -m "not pulling b changes" a^{tree}
有了这个,你就要求 git 创建一个新的修订对象,它有 a
和 b
作为父对象,它有 a
的树作为它的树(所以与 { 没有区别{1}}) 有我在那里提供的评论(随意调整)。将创建对象,并将 id 打印在标准输出上。您可以检查它以确保它是您想要的:
a
应该没有区别。然后你可以移动一个如果你喜欢它:
git diff that-id a
git log that-id
gitk that-id