gitsourcetree

Have SourceTree detect a rename even if the original file remains


I'm trying to convert some Javascript files to TypeScript files. I've renamed my move.js file to move.ts in my IDE (VSCode in this instance) and compiled with TSC to check if everything works. Now I want to commit my changes.

I don't know how to make SourceTree and/or Git understand that:

  1. My original file was renamed; and
  2. That file (with its new name) has some changes; and
  3. A new file with the original file's name was created;

Is that even possible? How do I use SourceTree (or failing that, the git command line tool) to indicate this status? Does it require two seperate commits?

Here's what SourceTree shows for the status:

SourceTree status

If I'd stage these files as is it would be committed as an edit+addition, which I don't want.

Here's what git status reports:

On branch TypeScriptConversion
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

  modified:   src/js/domain/move.js

Untracked files:
  (use "git add <file>..." to include in what will be committed)

  src/js/domain/move.ts

no changes added to commit (use "git add" and/or "git commit -a")

How do I tell SourceTree and/or git that my file was renamed, edited, and a new file with the same name entered in its place?


Solution

  • Separate the commits: do the rename in one commit, then do the add of the replacement for the original file in a second commit.