Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git rebase to stop just before each commit to then edit and rebase --continue

Tags:

git

I notice when I rebase and have a merge conflict, it has the staged changes for the current commit, so it is easy to find what was done in the commit and change it, but then you can also just do 'git rebase --continue' and it will apply the change with the same commit message as before.

Is there a way to force this to happen for specific commits, or all commits, so I can easily rebase and edit the previous changes I made to work with the changes I have rebased on? It seems like this would be much easier than just setting edit on all the commits and then doing 'git reset --soft HEAD~', so that the changes are visible and I can check they make sense for the new HEAD, editing, and then having to do 'git commit -m "message" '.

My use case is that the repository I am working with has had its file structure heavily refactored and git is unable to make the appropriate changes, but says the merge is successful.

Thanks!

like image 808
GDYendell Avatar asked Apr 27 '17 12:04

GDYendell


People also ask

Do I need to commit before git rebase -- continue?

For each change you make, you'll need to perform a new commit, and you can do that by entering the git commit --amend command. When you're finished making all your changes, you can run git rebase --continue . As before, Git is showing the commit message for you to edit.

How do I stop a rebase in progress?

To check out the original branch and stop rebasing, run "git rebase --abort".

What is git rebase -- edit todo?

By replacing the command "pick" with the command "edit", you can tell git rebase to stop after applying that commit, so that you can edit the files and/or the commit message, amend the commit, and continue rebasing.


1 Answers

I think what you are looking for is interactive rebasing and rewriting git history. It will let you squash commits as well as change the commit messages.

git rebase -i branch # <branch> should be the parent branch i.e. develop/master

Rewriting git history

# for instance
>>> git rebase -i branch
pick 8705209 first
edit 7979797 second # Use edit wherever you want to view and edit commit
squash 9793757 third # Use squash to squash commits into the previous one.
like image 69
hspandher Avatar answered Sep 17 '22 17:09

hspandher