Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "git reset --soft HEAD^" a single file?

Tags:

git

When I am splitting a commit during interactive rebase, I often would like to extract specific files from the last commit.

My current process is to

  1. Copy the last commit message to my clipboard,
  2. git reset --soft HEAD^ (last commit is undone, changes are staged)
  3. Unstage files I wanted extract
  4. Re-commit (pasting in the copied commit message)
  5. Add/commit the remaining files
  6. Continue with rebase

I feel like this would be simpler if I could soft reset a specific file.

like image 357
Rhinon Avatar asked Jan 30 '14 23:01

Rhinon


2 Answers

Are you trying to do git checkout $COMMIT_HASH some_file.ext?

You can use this to revert a file to its previous state, and git stages this change.

like image 190
mellowfish Avatar answered Nov 15 '22 10:11

mellowfish


It seems this does what you want :

git reset [-q] [commit] [--] paths… This form resets the index entries for all paths to their state at commit. (It does not affect the working tree, nor the current branch.)

This means that git reset is the opposite of git add .

like image 24
Emil Davtyan Avatar answered Nov 15 '22 11:11

Emil Davtyan