
Otherwise, the file is untracked and Git doesn't know about it and isn't managing any versions of it.Īn example of an untracked file would be a new file that hasn't been added to Git. This designation refers to whether or not Git knows about the file-that is, has someone previously added this file to Git? If this file has at least been added to the staging area at some point (and not removed), then Git knows about it, and is managing a version of it, so it is tracked by Git. So here we have saved our work for this particular file create_users.sh while the other one is still in our local repository and has not been stashed yet (as expected):ĪLSO READ: git show explained in-depth What are tracked and untracked files in Gitīefore we go ahead you must be familiar about tracked and untracked files. q: quit (any hunks that have already been selected will be stashed).
STASH MEANING FULL
You can hit ? for a full list of hunk commands. +# Modified on 20-07-2021 (1/1) Stash this hunk ? y Saved working directory and index state WIP on main: 1b6369c Added create_users.sh script Let's execute stash with -patch: git stash -pĭiff -git a/git_stash/create_users.sh b/git_stash/create_users.sh This will prompt for stashing each of the files.įor example, here I have made some changes on my branch: Stash selected files only (git stash -patch)īy default git stash will stash all the uncommitted changes but if you have a requirement to stash only some of the uncommitted changes then you can use -p|-patch argument. So now my git_examples repo is clean as new: git statusįollowing are the changes which are currently stashed:ĪLSO READ: git detached HEAD Explained Saved working directory and index state WIP on my-feature-branch: 1b6369c Added create_users.sh script Now I can't commit these changes as they are not complete so let me just save these changes in the stash while I work on other project: git stash No changes added to commit (use "git add" and/or "git commit -a")īut then I suddenly remembered that I also have to work a different project which is priority. " to discard changes in working directory) Here I have made some changes to one of the scripts under git_stash directory: git status I will be performing different operations under this directory during the course of this article. I have this repository git_examples under which I have created git_stash directory.

STASH MEANING HOW TO
Git stash store ĪLSO READ: git fetch vs git pull Explained Save uncommitted changes How to stash all the changes The syntax for the git stash command is as follows: git stash list However, because you have the stash, you haven't lost your uncommitted changes. After creating the stash and saving the uncommitted content, Git is basically doing a git reset -hard HEAD operation.That content can be in the staging area, in the working directory, or both. Each time the stash command is invoked and there is uncommitted content (since the last stash command), git creates a new element on the queue to save that content.By uncommitted changes, I mean items in either the staging area or the working directory that have been modified but not committed to the local repository.The git stash command saves a copy of your uncommitted changes in a queue, off to the side of your project.

