depreston
depreston

Reputation: 341

Remove merge without losing local commit

I have two branches called "task1" and "task2". Now I'm working in branch "task1".

I did a git merge task2 and it works properly. Now I'd like to write some code in "task1" and after that I want to remove that merge without losing changes that I just did.

How can I do it?

Upvotes: 0

Views: 366

Answers (3)

SwissCodeMen
SwissCodeMen

Reputation: 4885

Change to branch task1

git checkout task1

merge task2 in task1. This will generate a commit who appoints the HEAD to a specific commit

git merge task2

Make some changes on task1 and commit the changes

...

To find the commit-hash before merging the branches

git log

reset task1 before merging task1 to task2. With --soft the file changes will stay in your working tree.

git reset --soft <commit_before_merge>

Tutorial for undo a merge

Upvotes: 0

initanmol
initanmol

Reputation: 395

You can use git revert to undo all the changes introduced by the merge commit.

git log ## to get commit hash from merge
git revert <merge-commit-hash>

Find more detail on git revert here.

Upvotes: 0

eftshift0
eftshift0

Reputation: 30204

So, you would like to keep the content of the current branch task1 but only showing 1 single revision after its starting point (starting point of your explanation, that is)? If that is the case:

git checkout task1
git reset --soft HEAD~2
git commit -m "Merge and the last commit joined together, no merge will show up"

And you are done.

Upvotes: 1

Related Questions