1

In a git repo, I accidentally moved a file, A, to B, instead of deleting A and creating a completely new B.

How can I delete A and create a new B during a rebase?

XDR
  • 4,070
  • 3
  • 30
  • 54
  • In git there is no difference between 'moving `A` to `B`' and 'deleting `A` and creating `B`'. When git sees one file disappear and another appear, the similarity between the files' content is what determines whether it reports "a moved file' or "a deleted file and an added file'. Can you more clearly explain what behavior of git (and/or your repo) you want changed? Is the content of B wrong? Or are you just concerned about git saying that the file was moved? – Mark Adelsberger Sep 26 '19 at 13:53

1 Answers1

0

To answer your question, there's nothing you can do in a single commit to differentiate a delete+create from a rename. If you can separate the deletion and creation into separate commits, this will prevent Git from identifying the operation as a rename.

According to Wikipedia's Git article:

Git addresses the issue by detecting renames while browsing the history of snapshots rather than recording it when making the snapshot

"The issue" being the difficulty of tracking the history of a renamed file.

thelr
  • 1,134
  • 11
  • 30