Wednesday, May 19, 2021

Git Basics - stash untracked files and pop

By default 'git stash' will only aplies track files


git ls-files-> give list of files tracked by git. include man.txt

mate man.txt -> edited

git status -> modified: man.txt


create a new files

mate newfile.txt


git status

----------

Changes not staged for commit

modified: man.txt

Untracked files

modified: newfile.txt

git stash

git status -> still have untracked files in our working directory

Untracked files

modified: newfile.txt


git stash apply -> back to old state with untracked and tracked files

drop the last stash, do it now else you will forget

git stash drop

git stash list -> there won't be any result, no pending stash in this case


To include untracked files

git stash -u 

git status -> clean

git stash list -> can see one item

let's do some

mate README.md

git commit -am "quick fix after stash"

git status -> clean


Here we used "git stash apply" and "git stash drop"

let's do this in one command


git stash pop -> this will show status and drop last item from stash 


git status -> we have out modified file and new file (untracked file)


let's remove the new file using bash command

rm newfile.txt

git status -> 

---------------

Changes not staged for commit

modified: man.txt

git commit -am "updates to man.txt command after stash pop"

git status -> clean

No comments:

Post a Comment