Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

git - Automatic rebase to drop a commit that modifies a file?

I'm new to git rebase and doing something a bit wacky and stupid. So let's say I have these commits which all modify the same file file.txt

a -> b -> c -> d -> e

I want to just remove commit c.

My strategy for this is to rebase b onto d, keeping d's changes so it reads like this

a -> b -> d -> e

I'm trying to do this with this command

git rebase --rebase-merges --onto c^ c

This results in a failed merge, I've also tried it with -s ours but that fails as well.

This works when each commit modifies a different file, however.

What should I do to satisfy this goal?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In this case, you're almost certainly getting a conflict because there's really a conflict, and there isn't a way to avoid dealing with this. You'll have to resolve the conflict and then run git rebase --continue.

This works when each commit modifies a different file because commits that touch different files don't usually conflict (unless there's a rename or copy).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...