0

I have a problem in git and I need help. This is setup:

  • I have a feature branch in git. refactor_database
  • This feature branch is now ready to merge in master.
  • The first commit of this branch is 3 months old
  • There are no conflicts

previously there was one file

  • 1) "db/db.service.ts"

now there are 3 files:

  • 1) "db/db.service.ts"
  • 2) "indexed-db/indexed-db.service.ts"
  • 3) "sqlite/sqlite.service.ts"

1 (db.service.ts) previously had the contents of 2 (indexed-db.service) in it. Now 1 is only a wrapper, that forwards method calls to 2 or 3 depending on some conditions.

However I did a mistake 3 months ago and I did not realize it until now:

  • Git thinks 1 is the old file and has a ton of changes in it - actually it is a new file
  • Git thinks 2 is a completely new file. However it is just the the file, that used to be 1 (the file moved)

This screenshot makes the problem clear: I want the "+" to be @ db.service.ts and sqlite.service.ts.

indexed-db should be a rename of db.service instead of a new file(+)

enter image description here

My question is: Can i retrospectively repair this? If so, how?

Michael B
  • 1,660
  • 3
  • 28
  • 59

1 Answers1

1

You are facing one of git's limitations here. The only way git has to track a same file which has been renamed is by using heuristics, so depending on your commit, it may eventually not be able to understand it. A good practice to help git following moved files is to make unitary move commits.

Maybe you already know that and that is why you are asking for a way to amend your commit:

If I were you, I would look for the hash of the commit just before yours and git rebase -i <hash>.

The interactive rebase lets you "edit" a commit in the list. You could here amend your commit and make it unitary, then git rebase --continue.

Think about pushing in a new branch when you did this because you will not be able to push without forcing and, I'm cautious, I don't do that.

Maybe a look at this?

  • Thank you for your answer and your explanation. I will try with the interactive rebase in a new branch. If it doesn't work out, I just have to live with it. (And next time be more careful when renaming stuff) – Michael B Oct 16 '19 at 12:49