git > on committing renamed files

The aim is documenting renaming in git. The case is the renaming of files in the context of blogging for various reasons — a major change sometimes is followed by the bump of the timestamp necessary for Jekyll. I have used prefixes within filenames for semantic/versioning reasons, etc

commit rename automatically

  • rename file
  • stage the renamed file and nothing else
  • commit with commit -a -m <commit message> flag or (commit commit --all -m <commit message>)

- Git — git-commit Documentation

▶ git log --pretty=format:"%h%x09%an%x09%ad%x09%s" --name-status --date=short 91695bb pavol kutaj 2020-07-08 staleness R078 _posts/2020-06-02-staleness.md _posts/2020-07-08-staleness.mdmaster ↑1 +16 ~0 -1 ! ⚡ 2 minutes ago 
▶ git add 2020-07-09-git-rename-and-commit.md
master ↑1 +1 ~0 -0 | +15 ~0 -1 ! ⚡ 2 minutes ago
▶ git commit -a -m "rename example"
[master 78102c8] rename example 1 file changed, 0 insertions(+), 0 deletions(-) rename _posts/{2020-07-08-git-rename-and-commit.md =>
2020-07-09-git-rename-and-commit.md} (100%)
master ↑2 +15 ~0 -0 ! ⚡ 0 seconds ago
▶ git log --pretty=format:"%h%x09%an%x09%ad%x09%s" --name-status --date=short 78102c8 pavol kutaj 2020-07-08 rename example
R100 _posts/2020-07-08-git-rename-and-commit.md _posts/2020-07-09-git-rename-and-commit.md

benefits

  • the workflow below is faster than having to
  1. stage an addition of new an with git add <old_name>
  2. stage a removal of old file with git add <new_name>

r100 status — and similar

- from https://stackoverflow.com/a/53057010

Originally published at Pavol’s github KB.

Written by

today I learnt… | as a support eng of the wonderful Snowplow Analytics, expect everything around modern (postmodern?) business intelligence

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store