Config Router

  • Google Sheets
  • CCNA Online training
    • CCNA
  • CISCO Lab Guides
    • CCNA Security Lab Manual With Solutions
    • CCNP Route Lab Manual with Solutions
    • CCNP Switch Lab Manual with Solutions
  • Juniper
  • Linux
  • DevOps Tutorials
  • Python Array
You are here: Home / How can I git stash a specific file?

How can I git stash a specific file?

August 1, 2021 by James Palmer

EDIT: Since git 2.13, there is a command to save a specific path to the stash: git stash push . For example:
git stash push -m welcome_cart app/views/cart/welcome.thtml

OLD ANSWER:
You can do that using git stash –patch (or git stash -p) — you’ll enter interactive mode where you’ll be presented with each hunk that was changed. Use n to skip the files that you don’t want to stash, y when you encounter the one that you want to stash, and q to quit and leave the remaining hunks unstashed. a will stash the shown hunk and the rest of the hunks in that file.
Not the most user-friendly approach, but it gets the work done if you really need it.

I usually add to index changes I don’t want to stash and then stash with –keep-index option.
git add app/controllers/cart_controller.php
git stash –keep-index
git reset

The last step is optional, but usually, you want it. It removes changes from the index.

Warning
As noted in the comments, git stash –keep-index pushes everything onto the stash, both staged and unstaged. The –keep-index just leaves the index alone after the stash is done. This can cause merge conflicts when you later pop the stash.

Related

Filed Under: Uncategorized

Recent Posts

  • How do I give user access to Jenkins?
  • What is docker volume command?
  • What is the date format in Unix?
  • What is the difference between ARG and ENV Docker?
  • What is rsync command Linux?
  • How to Add Music to Snapchat 2021 Android? | How to Search, Add, Share Songs on Snapchat Story?
  • How to Enable Snapchat Notifications for Android & iPhone? | Steps to Turn on Snapchat Bitmoji Notification
  • Easy Methods to Fix Snapchat Camera Not Working Black Screen Issue | Reasons & Troubleshooting Tips to Solve Snapchat Camera Problems
  • Detailed Procedure for How to Update Snapchat on iOS 14 for Free
  • What is Snapchat Spotlight Feature? How to Make a Spotlight on Snapchat?
  • Snapchat Hack Tutorial 2021: Can I hack a Snapchat Account without them knowing?

Copyright © 2025 · News Pro Theme on Genesis Framework · WordPress · Log in