Advanced work with git stash

Advanced work with git stash

In Git, the most recent stash is always assigned the index 0, appearing as stash@{0}. When you create a new stash, all existing stashes are pushed down the stack (e.g., the previous 0 becomes 1). 

1. Identify which stash is yours

To see all your stashed entries and their assigned numbers, use:
git stash list 
This will output a list like this:
  • stash@{0}: WIP on master: 4fd1101... (Latest)
  • stash@{1}: On develop: updated files... 

2. View contents without applying

You can inspect the contents of any stash entry using the show command.
  • View a file summary (stat):
    git stash show stash@{0}
    (Shows only the list of files changed and the number of insertions/deletions)

  • View full code changes (diff):
    git stash show -p stash@{0}
    (The -p or --patch flag shows the actual line-by-line code changes)

  • View untracked files:
    git stash show --include-untracked stash@{0}

  • View a specific file from a stash:
    git diff stash@{0} -- path/to/file.txt
     
Quick reference commands
To do this...Run this command
List all stashesgit stash list
Peek at latest stash (summary)git stash show
Peek at latest stash (full code)git stash show -p
Peek at specific stash (e.g., #2)git stash show -p stash@{2}

3. create message along with git stash -p

by using the push subcommand with the -m (message) and -p (patch) flags together.
To stash specific parts of your code with a descriptive label, use:
git stash push -p -m "your custom message here"

Comments

Popular posts from this blog

Интересное о Формальдегиде

Открываем порт для сервера Minecraft на роутере mikrotik (команда для терминала в WinBox)