Stash Changes it Git
Stash Changes it Git
In this tutorial, we will know the steps involved to stash changes in the Git source control tool. We can stash local changes to store in a safe place using Git. Stashing a change removes the change and stores it so that we can apply later or delete the changes. The local changes will need to be committed to the remote GitHub repository.
Let’s run some commands to get a better understanding. Let’s create a file and then we stash it.
// We will stash this change and file public class StashingChanges { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Stashed File..."); } }
git Stash
hp@LAPTOP-3NKORD70 MINGW64 ~/SampleProject (master) $ git stash No local changes to save hp@LAPTOP-3NKORD70 MINGW64 ~/SampleProject (master) $ git add ^C hp@LAPTOP-3NKORD70 MINGW64 ~/SampleProject (master) $ git add src/StashingChanges.java hp@LAPTOP-3NKORD70 MINGW64 ~/SampleProject (master) $ git stash Saved working directory and index state WIP on master: ea95ebc Merge pull request #3 from yskumar007/git-branch-demo hp@LAPTOP-3NKORD70 MINGW64 ~/SampleProject (master) $ git status On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean
Git stash List
To see which stashes we have stashed, we can use
$ git stash list
If we want to apply all the stashes we can use the apply command
$ git stash apply
hp@LAPTOP-3NKORD70 MINGW64 ~/SampleProject (master) $ git stash list stash@{0}: WIP on master: ea95ebc Merge pull request #3 from yskumar007/git-branch-demo hp@LAPTOP-3NKORD70 MINGW64 ~/SampleProject (master) $ git stash apply On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: src/StashingChanges.java
Git Tutorial on this website can be found at:
https://www.testingdocs.com/git-tutorials/