vitalyster
vitalyster

Reputation: 5266

Mark file as "renamed" when squashing commits

When I move tracked files in the repository git shows in commit info "file xxx renamed from yyy".

Now I'm trying to squash two commits where file was deleted in first commit and added again in second commit (in different directory). In a resulting commit I didn't see "renamed", only "deleted" and "added".

How to help git to understand this and show "renamed" for this file?

Upvotes: 1

Views: 404

Answers (1)

torek
torek

Reputation: 489073

Git finds (detects) renames dynamically, at the time it makes the comparison.

There are a number of options that control whether Git tries at all, and if so, what it considers "sufficiently similar" to make it think of a file as renamed.

How you can make Git present something as a rename depends on:

  • Your Git version. 2.9 and later turn rename detection on by default for git diff.
  • The command you are using. Git has rename detection turned on by default for git merge, even in older versions of Git. The git status command always does rename detection.
  • The similarity of the files. Exact matches are easy and are found the most often.
  • Options you supply to the commands. See Git doesn't detect rename when file has been modified significantly after move for instance. These also depend on the commands; for instance, while git status always has detection enabled, it has no configuration for thresholds.
  • Configuration entries (in your global Git configuration and/or your per-repository config). You can override Git's enable/disable defaults for git diff by setting diff.renames, and override its maximum number of files in its rename-detection queue by setting diff.renameLimit.

For (much) more about git diff's rename detection—in particular, the method Git uses to determine file identity across two commits—see Git Diff of same files in two directories always result in "renamed".

Upvotes: 2

Related Questions