Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo file change during rebase

Tags:

git

What i'm looking for is how to checkout a file during a git rebase merge conflict. The situation I ran into today was during a git rebase I had to manually merge the file, and I messed it up. During normal git usage I would just issue a git checkout myfile, and I tried that but the file was still in the state I left it. What I wanted in this case was the file in its original failed merge state with the conflict markers so I could give it another go. I ended up aborting the rebase and trying it again but I'd like something less drastic. What am I missing?

like image 598
Brandon Avatar asked Jan 12 '16 16:01

Brandon


People also ask

How do I undo a pull in rebase?

You can run git rebase --abort to completely undo the rebase. Git will return you to your branch's state as it was before git rebase was called. You can run git rebase --skip to completely skip the commit.

How do I undo a file in git?

If you have committed changes to a file (i.e. you have run both git add and git commit ), and want to undo those changes, then you can use git reset HEAD~ to undo your commit.


1 Answers

git checkout -m file

To reproduce the automerged result (with conflict markers) of a conflicted path file, using the three versions (base, ours and theirs) recorded in the index. With versions of git up to v1.6.6 (released recently), however, this is only possible until we "git add file" to mark the path as resolved, at which point the three versions are discarded from the index and replaced with the result of the merge.

Ref: http://gitster.livejournal.com/43665.html

like image 180
Sazzad Hissain Khan Avatar answered Oct 12 '22 00:10

Sazzad Hissain Khan