Urgent.News

What's breaking now, across thousands of outlets.

Tech

git commit -m with a path argument doesn't commit what you staged

git commit -m "msg" -- doesn't commit what you staged I'd staged a handful of files, run a narrow git commit -m "fix: ..." -- path/to/file.rs , and assumed the diff that landed matched what I'd git add ed. It didn't. It matched whatever was sitting on disk in that file at the moment the commit ran, which happened to include a few uncommitted lines from a different working session sharing the same…

When using the command `git commit -m "msg" -- path/to/file.rs`, it does not commit the files that you have staged. Instead, it commits only the current working-tree content of the specified file, disregarding the staged changes. This behavior can be dangerous because it commits whatever is on disk at the time of the commit, which may include uncommitted changes from a different session.

The index still affects other files in the repository, but for the paths named in the pathspec, git uses the current state of those files on disk. Running `git add --cached` beforehand does not resolve this issue, as the pathspec form of the commit command overrides the staged content. This problem is more noticeable in shared work environments, where multiple users may be editing the same files simultaneously.

To avoid this issue, it is recommended to stage exactly what you intend to commit before running the commit command. Running `git diff -- path/to/file.rs` after committing can help verify that the changes committed are indeed your own.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

A double-quoted $HOME sent three of my directories nowhere I could find them

A double-quoted $HOME sent three of my directories nowhere I could find them I was calling into WSL from a PowerShell script, the way I do a dozen times a day: build a command string, hand it to wsl…

  • PowerShell script inadvertently sent directories nowhere
  • Double-quoted $HOME expanded prematurely
  • Single quotes solution created directories correctly

Deleting files inside WSL doesn't shrink the disk they lived on

Deleting files inside WSL doesn't shrink the disk they lived on WSL2 keeps its entire Linux filesystem inside one file on the Windows side, a virtual hard disk with a .vhdx extension.

  • Files inside WSL do not shrink disk automatically.
  • Use fstrim, wsl --shutdown, and Optimize-VHD to manually reduce size.
  • Cleanup reduces size by 672GB in example scenario.

More from Thursday 3 September →