2/25/2023 0 Comments Git stash command![]() List all the files that changed when the stash entry was created: Stash only one file (instead of all the changes): You can create a stash for uncommitted changes by running:Īdd a message to your stash for easier identification afterwards: at the end!)Įach repository has its own unique stash and you can end up with entries from different branches in that repository’s stash. If you don’t care about the changes and just want to discard unstaged changes (changes you did not “git add” yet), you can just run git checkout. The key point for git stash is to save the changes for later. If later on you decide that your first solution was the best one, you can stash this new code and retrieve the previous solution from the stash. You can stash the current changes so your new branch gets “reset” to the same state as when it was created and you can try a different solution. ![]() You make a few changes but you think you can create a different solution for that issue. ![]() This is almost like having a branch within a branch: imagine that you created a branch for some new work. You can now checkout a different branch and start new work. In this way, when you run “git status”, you see that your repo is back to the same state it was when you first cloned it or created that branch: the recent changes are not visible anymore but they are saved in case you want to go back and work on them again. You can then ask git to take the current changes and save they aside. ![]() When you have some work in progress but you are not ready to create a commit yet (maybe you are just exploring some options or the work is not completed yet) and you need to switch branches OR you want to go back to start point but you want to keep the changes for later. It allows you to save your work in progress out of your way, meaning, without the need to create a commit, and access that work later. But if you start collaborating and need to switch between a new feature work to fixing a bug, for example, git stash is very helpful. In my opinion this is one command that might not be super useful if you are just starting to code or you are the only person working on a personal project. One git command I started using not too long ago is git stash. However, you can be a lot more productive if you go beyond the basics. It's similar to a shelveset in Team Foundation Version Control, except that it's stored locally in your Git repository and not synced up to the server.Git is a very useful tool for software development and you only need to know a few commands to get most of the job done.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |