Skip to content

Commit c42e154

Browse files
committed
Grab a file from a stash. Restore file as per a commit hash
1 parent 90d98ea commit c42e154

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* [Apply any stash without deleting from the stashed list](https://github.com/git-tips/tips#apply-any-stash-without-deleting-from-the-stashed-list)
4444
* [Apply last stashed state and delete it from stashed list](https://github.com/git-tips/tips#apply-last-stashed-state-and-delete-it-from-stashed-list)
4545
* [Delete all stored stashes](https://github.com/git-tips/tips#delete-all-stored-stashes)
46+
* [Grab a single file from a stash](https://github.com/git-tips/tips#grab-a-single-file-from-a-stash)
4647
* [Show all tracked files](https://github.com/git-tips/tips#show-all-tracked-files)
4748
* [Show all untracked files](https://github.com/git-tips/tips#show-all-untracked-files)
4849
* [Show all ignored files](https://github.com/git-tips/tips#show-all-ignored-files)
@@ -75,6 +76,7 @@
7576
* [Undo assume-unchanged.](https://github.com/git-tips/tips#undo-assume-unchanged)
7677
* [Clean the files from `.gitignore`.](https://github.com/git-tips/tips#clean-the-files-from-gitignore)
7778
* [Restore deleted file.](https://github.com/git-tips/tips#restore-deleted-file)
79+
* [Restore file to a specific commit-hash](https://github.com/git-tips/tips#restore-file-to-a-specific-commit-hash)
7880
* [Always rebase instead of merge on pull.](https://github.com/git-tips/tips#always-rebase-instead-of-merge-on-pull)
7981
* [List all the alias and configs.](https://github.com/git-tips/tips#list-all-the-alias-and-configs)
8082
* [Make git case sensitive.](https://github.com/git-tips/tips#make-git-case-sensitive)
@@ -331,6 +333,17 @@ __Alternatives:__
331333
git stash drop <stash@{n}>
332334
```
333335

336+
## Grab a single file from a stash
337+
```sh
338+
git checkout <stash@{n}> -- <file_path>
339+
```
340+
341+
342+
__Alternatives:__
343+
```sh
344+
git checkout stash@{0} -- <file_path>
345+
```
346+
334347
## Show all tracked files
335348
```sh
336349
git ls-files -t
@@ -527,6 +540,11 @@ git clean -X -f
527540
git checkout <deleting_commit>^ -- <file_path>
528541
```
529542

543+
## Restore file to a specific commit-hash
544+
```sh
545+
git checkout <commit-ish> -- <file_path>
546+
```
547+
530548
## Always rebase instead of merge on pull.
531549
```sh
532550
git config --global branch.autosetuprebase always

tips.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@
125125
"title": "Delete all stored stashes",
126126
"tip": "git stash clear",
127127
"alternatives": ["git stash drop <stash@{n}>"]
128+
}, {
129+
"title": "Grab a single file from a stash",
130+
"tip": "git checkout <stash@{n}> -- <file_path>",
131+
"alternatives": ["git checkout stash@{0} -- <file_path>"]
128132
}, {
129133
"title": "Show all tracked files",
130134
"tip": "git ls-files -t"
@@ -228,6 +232,9 @@
228232
}, {
229233
"title": "Restore deleted file.",
230234
"tip": "git checkout <deleting_commit>^ -- <file_path>"
235+
}, {
236+
"title": "Restore file to a specific commit-hash",
237+
"tip": "git checkout <commit-ish> -- <file_path>"
231238
}, {
232239
"title": "Always rebase instead of merge on pull.",
233240
"tip": "git config --global branch.autosetuprebase always"

0 commit comments

Comments
 (0)