From the course: Working with LinkedIn Learning Exercise Files on GitHub

Stash changes with Stash - GitHub Tutorial

From the course: Working with LinkedIn Learning Exercise Files on GitHub

Stash changes with Stash

- [Instructor] Before you switch from one branch to another in a GitHub repository, it's a good idea to resolve your changes. You can resolve changes by saving or committing them locally. You can roll back your changes, meaning you're going back to the old version of the code or you can do something called stashing your changes. Stash is a Git feature and you can get to that feature through IntelliJ IDEA. Now, let's say I wanted to switch to a new branch and I've made a change. I'll go to my Commit window. I'll choose main.java and press Command + D on Windows or Control + D on Mac and this will open the Diff window and I'll see my change listed here. I'll close that window and now if I try to go to another branch, say 04_02e, I'll be able to do that but this can get confusing because then you might be saving your changes to the wrong branch. Let's say what you really want to do is save your changes temporarily and then come back to them later. So I'll once again check out the beginning state of the video. And now I'll go to the menu and I'll choose Git, Uncommitted Changes, Stash Changes. Each stash must have a message. I'll call this saving my changes. I'll create the stash and when I do that, my changes go away. Now, when that happens, in IntelliJ IDEA, you might run into a weird bug, which is your Git window goes away and an old window named Version Control appears. If that happens, close the project and then reopen it and the Git window should reappear again. And again, that's a weird bug that you might encounter. Now, I'll come back up here and I'll switch to 04_02e. Check it out. I could now make changes to that branch and commit or roll them back. I can come back now to 04_02b, the beginning state and now let's say I want to restore those changes. I'll go to the menu again and choose Git, Uncommitted Changes, Unstash Changes. I'll see a list of my stashes, I'll select and apply the stash. If you run into this error, it means that you have changes that have to be resolved. So I'll get out of here by pressing Escape. I'll go to the Commit window. I'll see this is the file that's causing me the problem. I'll select it and I'll click Roll Back, meaning I don't need whatever changes IntelliJ made. Then I'll once again try to unstash. I'll select Git, Uncommitted Changes, Unstash Changes. And I'll apply the stash and my changes have been restored. So stashing and unstashing is an easy way to temporarily save your changes without committing them locally or without rolling them back.

Contents