Skip to content

Commit cf260b7

Browse files
committed
Merge pull request #43 from samarpanda/single-file-from-stash
Grab a file from stash / commit-hash!
2 parents 90d98ea + e416adc commit cf260b7

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@
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)
4950
* [Create new working tree from a repository (git 2.5)](https://github.com/git-tips/tips#create-new-working-tree-from-a-repository-git-25)
5051
* [Create new working tree from HEAD state](https://github.com/git-tips/tips#create-new-working-tree-from-head-state)
52+
* [Untrack files without deleting](https://github.com/git-tips/tips#untrack-files-without-deleting)
5153
* [Before deleting untracked files/directory, do a dry run to get the list of these files/directories](https://github.com/git-tips/tips#before-deleting-untracked-filesdirectory-do-a-dry-run-to-get-the-list-of-these-filesdirectories)
5254
* [Forcefully remove untracked files](https://github.com/git-tips/tips#forcefully-remove-untracked-files)
5355
* [Forcefully remove untracked directory](https://github.com/git-tips/tips#forcefully-remove-untracked-directory)
@@ -75,6 +77,7 @@
7577
* [Undo assume-unchanged.](https://github.com/git-tips/tips#undo-assume-unchanged)
7678
* [Clean the files from `.gitignore`.](https://github.com/git-tips/tips#clean-the-files-from-gitignore)
7779
* [Restore deleted file.](https://github.com/git-tips/tips#restore-deleted-file)
80+
* [Restore file to a specific commit-hash](https://github.com/git-tips/tips#restore-file-to-a-specific-commit-hash)
7881
* [Always rebase instead of merge on pull.](https://github.com/git-tips/tips#always-rebase-instead-of-merge-on-pull)
7982
* [List all the alias and configs.](https://github.com/git-tips/tips#list-all-the-alias-and-configs)
8083
* [Make git case sensitive.](https://github.com/git-tips/tips#make-git-case-sensitive)
@@ -331,6 +334,17 @@ __Alternatives:__
331334
git stash drop <stash@{n}>
332335
```
333336

337+
## Grab a single file from a stash
338+
```sh
339+
git checkout <stash@{n}> -- <file_path>
340+
```
341+
342+
343+
__Alternatives:__
344+
```sh
345+
git checkout stash@{0} -- <file_path>
346+
```
347+
334348
## Show all tracked files
335349
```sh
336350
git ls-files -t
@@ -356,6 +370,17 @@ git worktree add -b <branch-name> <path> <start-point>
356370
git worktree add --detach <path> HEAD
357371
```
358372

373+
## Untrack files without deleting
374+
```sh
375+
git rm --cached <file_path>
376+
```
377+
378+
379+
__Alternatives:__
380+
```sh
381+
git rm --cached -r <directory_path>
382+
```
383+
359384
## Before deleting untracked files/directory, do a dry run to get the list of these files/directories
360385
```sh
361386
git clean -n
@@ -527,6 +552,11 @@ git clean -X -f
527552
git checkout <deleting_commit>^ -- <file_path>
528553
```
529554

555+
## Restore file to a specific commit-hash
556+
```sh
557+
git checkout <commit-ish> -- <file_path>
558+
```
559+
530560
## Always rebase instead of merge on pull.
531561
```sh
532562
git config --global branch.autosetuprebase always

tips.json

Lines changed: 11 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"
@@ -140,6 +144,10 @@
140144
}, {
141145
"title": "Create new working tree from HEAD state",
142146
"tip": "git worktree add --detach <path> HEAD"
147+
}, {
148+
"title": "Untrack files without deleting",
149+
"tip": "git rm --cached <file_path>",
150+
"alternatives": ["git rm --cached -r <directory_path>"]
143151
}, {
144152
"title": "Before deleting untracked files/directory, do a dry run to get the list of these files/directories",
145153
"tip": "git clean -n"
@@ -228,6 +236,9 @@
228236
}, {
229237
"title": "Restore deleted file.",
230238
"tip": "git checkout <deleting_commit>^ -- <file_path>"
239+
}, {
240+
"title": "Restore file to a specific commit-hash",
241+
"tip": "git checkout <commit-ish> -- <file_path>"
231242
}, {
232243
"title": "Always rebase instead of merge on pull.",
233244
"tip": "git config --global branch.autosetuprebase always"

0 commit comments

Comments
 (0)