2

I was trying to merge my local branch with my development branch (both are local, but development is up to date with remote development branch). After I did rebase, I got few conflicts, and when I solved them, I noticed that while merging one file I disregarded development branch commit for it. I checked out this file to latest commit, but now it is being shown as having changes (both Eclipse and git status show it needs to be commited).

Command sequence:

(local_dev_branch)
git pull
git checkout local_branch_from_dev
(local_branch_from_dev)
git rebase local_dev_branch
(conflicts appear)
git mergetool 
git rebase --continue
(noticed wrong file)
git checkout newest_commit_id wrong_file
git status
(and it shows that wrong_file is modified)

I am new to github, so this is still a bit confusing for me. Is it possible to somehow restore the file without having to commit it again later?

CrazySabbath
  • 1,164
  • 3
  • 10
  • 28

1 Answers1

1

In general, when your working directory is clean and you do a checkout of a previous version of a file, the file will of course be shown as changed. In comparison to the latest state of your repository (i.e. the HEAD commit of your branch), the file content did change.

What's wrong with committing the new version?

Alternatively, you can reset to the state before the rebase and do it again, this time taking the right version of the file from the start (assuming things went wrong during the merge while rebasing). See this answer on how to undo a rebase.

kowsky
  • 7,265
  • 1
  • 23
  • 37
  • I don't want to commit it, because there are no changes. I had older version of the file and tried to rebase/merge to newer version. Unfortunately I made a mistake with meld during merge, and had to checkout to newest commit. – CrazySabbath Jul 21 '17 at 07:47
  • When you reset a file to another version, there most certainly is a change in that file. That's why git shows it as changed. Or am I missing something here? – kowsky Jul 21 '17 at 07:50
  • You are not, I am just really confused and trying to process this all. – CrazySabbath Jul 21 '17 at 07:56
  • See [this answer](https://stackoverflow.com/a/135614/7598462) on how to undo a rebase. – kowsky Jul 21 '17 at 08:03
  • Read that answer after you suggested resetting the state and it worked just as I wanted. Made correct merge/rebase this time. Accepting your answer. – CrazySabbath Jul 21 '17 at 08:14
  • Consider literature like the [pro git book](https://git-scm.com/book/en/v2) or other sources listed in the [git tag info](https://stackoverflow.com/tags/git/info) to deepen your understanding of git and reduce confusion in the future :) – kowsky Jul 21 '17 at 08:17