AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Git stash apply vs pop8/30/2023 To the right of the sidebar, under "Stashed changes", click Discard. To the right of the sidebar, under "Stashed changes", click Restore. In the left sidebar, in the "Changes" tab, click Stashed Changes. If you are not already on the branch where the changes are stashed, in the repository bar, click Current Branch, then click the branch with stashed changes. For more information, see " Managing branches in GitHub Desktop." Stashing changes If you use GitHub Desktop to switch branches while you have saved, but not committed, changes, GitHub Desktop will prompt you to stash the changes or bring them to the other branch. After you stash changes on a branch, you can safely change branches or make other changes to your current branch. If you use GitHub Desktop to stash changes, all unsaved changes will be stashed. You can only stash one set of changes at a time with GitHub Desktop. When you stash changes, the changes are temporarily removed from the files and you can choose to restore or discard the changes later. Then I needed to quickly produce a fix for something so I stashed my changes (git stash) edited file (vi file) committed (git commit) popped stash (git stash pop) This resulted in Conflict. If you have saved changes that you are not ready to commit yet, you can stash the changes for later. 24 I have a local git repository and had several modified files. I'll have to figure out what category they are in, that they had to be manually deleted.To apply your changes to your repository, you must save the files and then commit the changes to a branch. Interestingly, of my ~30, 4 files still remained after cleaning (buried in subdirectories). Ultimately, I used git clean -f -d -x to remove the ignored files. It is unfortunate that I couldn't figure out a way to start a merge session with them. So the pop failed, essentially saying it didn't want to restore my stashed ignored files on top of files that were still there. That is because the checkout of master only affected committed files - it didn't wipe the ignored files. When I checked out my branch and tried to pop, my ignored files were still there from before the stash save. Git status showed me tracked and untracked, but my activities didn't clean up the ignored files.ĭetails: I had used git stash save -a, checked out the master to compile and see original behavior, then tried to put it all back to continue editing. My similarly blocked pop operation was because leftover ignored files (see the. Even without changing working directories those options can sometimes create a stash you can't just apply back. PPS, You may need this technique after just using stash with -patch and/or -include-untracked. Sometimes needed even when you haven't made working directory changes Keep in mind that branches and tags are really just references to commits, so in many ways stashes, branches, and tags are just different ways of pointing at a commit (and its history). When you apply/pop you are doing something similar to cherry-picking it into your current branch. PS, It is tempting to think of a stash as a patch (just like it is tempting to think of a commit as a patch), but a stash is actually a commit against the HEAD when it was created. git symbolic-ref HEAD refs/heads/ORIGINALBRANCHīackground Stashes are commits likes branches/tags (not patches) The end result will be your additional stash changes in your working copy. It will switch back to your original branch and index without changing your working copy. If you just stashed while keeping some staged changes, then committed, and all you want to do is get the additional changes that where not staged when you stashed you can do the following. Option 2 - Reset original branch to match stash (limited changes since stash) If there are conflicts then handle them normally (one of the advantages of this approach is you can see and resolve conflicts). Commit your changes in STASHBRANCH, rebase it on ORIGINALBRANCH, then switch to ORIGINALBRANCH and rebase/merge the STASHBRANCH changes over it. If you have done a lot of changes in your ORIGINALBRANCH, then you are probably best treating STASHBRANCH like any local branch. Option 1 - Rebase stash branch normally (lots of changes since stash) What you do next depends on the relationship between the stash and where your target branch (which I will call ORIGINALBRANCH) is now. The following creates a branch based on the HEAD when the stash was created and then applies the stash (it does not commit it). It works well because a stash really is a commit under the covers (see PS). This is actually a useful general technique for working with stashes even when you don't have the listed error. Once it is a branch you can work normally in git using the normal branch-related techniques/tools you know and love. The best way to do this is to convert the stash to a branch. But I personally prefer to stay "within git". As mentioned by you can manually delete the files it is complaining about, switch branches, and then manually add them back.
0 Comments
Read More
Leave a Reply. |