- Git Stash Github Desktop App
- Git Stash Github Desktop Download
- Stash App Github
- Git Stash Github Desktop Version
A git choose-your-own-adventure!ⓡ
Warning! Javascript has been disabled. This means that you will not get the bread crumbs representing what path you took. If you need further help, copy-pasting these bread crumbs would be extremely useful to anyone trying to provide help to you or improve this website.
GitHub Desktop Focus on what matters instead of fighting with Git. Whether you're new to Git or a seasoned user, GitHub Desktop simplifies your development workflow. Download for macOS Download for Windows (64bit) Download for macOS or Windows (msi) Download for Windows. By downloading, you agree to the Open Source Applications Terms. Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.
This document is an attempt to be a fairly comprehensive guide torecovering from what you did not mean to do when using git. It isn'tthat git is so complicated that you need a large document to take careof your particular problem, it is more that the set of things that youmight have done is so large that different techniques are neededdepending on exactly what you have done and what you want to havehappen.
If you have problems after clicking through this document, pleasecopy-paste the 'Path' you took (what links you clicked on,automatically presented to you if javascript is available) when askingfor further help, since doing so will explain very precisely what youwere trying to do, and that you at least tried to help yourself.
First step
Scenario: You just ran git push, sending your changes to GitHub, now you realize there's a problem with one of those commits. You'd like to undo that commit. Undo with: git revert What's happening: git revert will create a new commit that's the opposite (or inverse) of the given SHA. If the old commit is 'matter', the new. The command git stash is used to stash the changes in a dirty working directory away. You can list all stashed change using the command git stash list, crayon-60814822a92be404525668/ Every time you stash your working directory, git will save the state of working directory into somethine which mantins history of stash tree.
Strongly consider taking abackupof your current working directory and .git to avoid any possibility oflosing data as a result of the use or misuse of these instructions. Wepromise to laugh at you if you fail to take a backup and regret itlater.
Answer the questions posed by clicking the link for that section.A section with no links is a terminal node and you should have solvedyour problem by completing the suggestions posed by that node (if not,then report the chain of answers you made on #git or some other gitresource and explain further why the proposed answer doesn't help).This is not a document to read linearly.
Are you trying to find that which is lost or fix a change that was made?
Git Stash Github Desktop App
Have you committed?
Discard everything or just some things?
How to save uncommitted changes
There are five ways you can save your uncommitted change. I alsosuggest you read Pro Git as theseare pretty basic git operations.
Description | Command |
---|---|
Commit them on the local branch. | git commit -am 'My descriptive message' |
Commit them on another branch, no checkout conflicts. | git checkout otherbranch && git commit -am 'My descriptive message' |
Commit them on another branch, conflicts. | git stash; git checkout otherbranch; git stash apply; : 'resolve conflicts'; git commit -am 'My descriptive message'; git stash drop |
Commit them on a new branch. | git checkout -b newbranch; git commit -am 'My descriptive message' |
Stash them for a rainy day. | git stash save 'my descriptive name' |
Using git add -p
to add/commit only somechanges to make multiple commits is left as an exercise for thereader.
How to undo all uncommitted changes
So you have not yet committed and you want to undo everything.Well, bestpractice is for you to stash the changes in case you were mistakenand later decide that you really wanted them afterall. git stash save 'description ofchanges'
. You can revisit those stasheslater git stash list
and decide whetherto git stash drop
them after some time haspast. Please note that untracked and ignored files are not stashed bydefault. See '--include-untracked' and '--all' for stash options tohandle those two cases.
However, perhaps you are confident (or arrogant) enough to know forsure that you will never ever want the uncommitted changes. If so,you can run git reset --hard
, howeverplease be quite aware that this is almost certainly a completelyunrecoverable operation. Any changes which are removed here cannot berestored later. This will not delete untracked or ignored files.Those can be deleted with git clean-nd
git clean -ndX
respectively,or git clean -ndx
for both at once. Well,actually those command do not delete the files. They show what fileswill be deleted. Replace the 'n' in '-nd…' with 'f' to actuallydelete thefiles. Bestpractice is to ensure you are not deleting what you should not bylooking at the moribund filenames first.
How to undo some uncommitted changes
Do you have uncommitted stuff in your working directory?
Have you pushed?
Do you want to discard all unpushed changes on this branch?
Discarding all local commits on this branch
Replacing all branch history/contents
Is the commit you want to fix the most recent?
Do you want to remove or change the commit message/contents of the last commit?
Removing the last commit
If you want to 'uncommit' the commits, but keep the changes aroundfor reworking, remove the'--hard': git reset HEAD^
which will evictthe commits from the branch and from the index, but leave the workingtree around.
If you want to save the commits on a new branch name, thenrun git branchnewbranchname
before doingthe git reset
.
Reworking the last commit
If you want to reorder commits, split them, merge them together, orotherwise perfect the commits, you shouldexplore PostProduction Editing Using Git.
Moving a commit from one branch to another
So, you have a commit which is in the wrong place and you want tomove it from one branch to another. In order to do this, you willneed to know the SHA of the first and last commit (in a continuousseries of commits) you want to move (those values are the same if youare moving only one commit), the name of the branch you are moving thecommit from, and the name of the branch you are moving the commit to.In the example below, I will name these four values $first, $last,$source, and $destination (respectively). Additionally, you will needto use a noncebranch as a placeholder. I will call the nonce branch 'nonce' in thefollowing example. However, you may use any branch name that is notcurrently in use. You can delete it immediately after you aredone.
Remember that when you substitute $first in the command above, leavethe '^' alone, it is literal.
Use gitk --all --date-order
to check tomake sure the move looks correct (pretending that nonce is thedestination branch). Please check very carefully if you were tryingto move a merge, it may have been recreated improperly. Ifyou don't like the result, you may delete the nonce branch(git branch -D nonce
) and try again.
However, if everything looks good, we can move the actualdestination branch pointer to where nonce is:
If you double-checked with gitk --all--date-order
, you would see that the destination branch lookscorrect. However, the commits are still on the source branch as well.We can get rid of those now:
Using gitk --all --date-order
one lasttime, you should now see that the commits on the source branch havegone away. You have successfully moved the commits. Please check verycarefully if merges occurred after the commits which were deleted.They may have been recreated incorrectly. If so you caneither undo thedelete or try to delete the bad merge and try to recreate itmanually, or create a fake (--ours) merge from the same SHA so thatgit is aware that the merge occurred.
Updating the last commit's contents or commit message
Php code generator. If you want to do something more sophisticated that what '--amend'allows, please investigate reworking thelast commit.
Do you want to remove an entire commit?
Removing an entire commit
Do you want to remove/change/rename a particular file/directory from all commits during all of git's history
Changing all commits during all of git's history
Use The BFG to remove unwanted data, like big files or passwords,from Git repository history.
The BFG is a simpler,faster alternative to git filter-branch
,specifically designed for cleansing bad data out of your Git repositoryhistory - it operates over all branches and tags in your project topurge data you don't want retained anywhere. Someexamples:
Remove all blobs bigger than 1 megabyte (to make your repo take up less space):
Replace all passwords listed in a file with ***REMOVED***
wherever they occur in your repository :
Arbitrarily changing all commits during all of git's history
git filter-branch
is a powerful, complexcommand that allows you to perform arbitary scriptable operations on allcommits in git repository history. This flexibility can make it quite slowon big repos, and makes using the command quite difficult, so I will simplypoint you at the manual pageand remind youthat bestpractice is to always use '--tag-name-filter cat ----all'
unless you are really sure you know what you aredoing.
BTW, this is the one command I referred to earlier which willupdate all tags and branches, at least if you use the best practicearguments.
Is a merge commit involved?
Changing a single commit involving only simple commits
You will be dumped in an editor with a bunch of lines starting withpick. The oldest commit, the one you are probably interested inchanging, is first. You will want to change the 'pick' to 'reword' or'edit', or perhaps even 'squash' depending on what your goal is.Please read the manual pagefor more information. A documenton Post-ProductionEditing using Git goes through much of the major uses of gitrebase is some detail. The use case is a little different, but thefundamental techniques are not.
When using 'edit', to change contents or author, when you aredumped into the shell to make your change, well make yourchange, git add
as normal, and thenrun git commit --amend
(including changingthe author information with --author). When you are satisfied, youshould run git rebase --continue
Changing a single commit involving a merge
Oh dear. This is going to get a little complicated. It should allwork out, though. You will need to usea nonce branch as aplaceholder. I will call the nonce branch 'nonce' in the followingexample. However, you may use any branch name that is not currentlyin use. You can delete it immediately after you are done.
Identify the SHA of the commit you wish to modify.
You can do this using
gitk --date-order
or usinggit log --graph --decorate--oneline
You are looking for the 40 character SHA-1 hash ID(or the 7 character abbreviation). Yes, if you know the '^' or'~' shortcuts you may use those.Remember the name of the branch you are currently on
The line with a star on it in the
gitbranch
output is the branch you are currently on. I will use'$master' in this example, but substitute your branch name for'$master' in the following commands.Create and checkout a nonce branch pointing at that commit.
Obviously replace 'SHA' with the reference you want to modify.
Modify the commit
You need to get the index into the correct state you wish thecommit to reflect. If you are changing the commit message only, youneed do nothing. If you are changing the file contents, typically youwould modify the working directory and use
gitadd
as normal.Note if you wish to restore a file to a known good state, you canuse
git checkout GOODSHA --path/to/filename
.Once the index is in the correct state, then you canrun
git commit --amend
to update the lastcommit. Yes, you can use '-a' if you want to avoidthegit add
suggested in the previousparagraph.If the commit you are updating is a merge commit, ensure that the logmessage reflects that.
Put the remaining commits after the new one you just created
Remembering to substitute the correct branch name for $master
Validate that the topology is still good
If some of the commits after the commit you changed are mergecommits, please be warned. It is possiblethat
git rebase -p
will be unable toproperly recreate them. Please inspect the resulting mergetopologygitk --date-order HEAD ORIG_HEAD
to ensure that git did want you wanted. If it did not, there is notreally any automated recourse. You can reset back to the commitbefore the SHA you want to get rid of, and then cherry-pick the normalcommits and manually re-merge the 'bad' merges. Or you can justsuffer with the inappropriate topology (perhaps creating fakemergesgit merge --ours otherbranch
sothat subsequent development work on those branches will be properlymerged in with the correct merge-base).Delete the nonce branch
You don't need it. It was just there to communicate an SHA betweentwo steps in the above process.
git branch -dnonce
Can you make a positive commit to fix the problem and what is the fix class?
Rewritingpublic history is a bad idea. It requires everyone else to dospecial things and you must publicly announce your failure. Ideallyyou will create either a commit to just fix the problem, or anew git revert
commit to create a newcommit which undoes what the commit target of the revert did.
Making a new commit to fix an old commit
Making a new commit to restore a file deleted earlier
Reverting an old simple pushed commit
Reverting a merge commit
Oh dear. This is going to get complicated.
To create an positive commit to remove the effects of a mergecommit, you must first identify the SHA of the commit you want torevert. Dazn canada reviews. You can do this using gitk--date-order
or using git log --graph--decorate --oneline
You are looking for the 40 character SHA-1hash ID (or the 7 character abbreviation). Yes, if you know the'^' or '~' shortcuts you may use those.
Git Stash Github Desktop Download
Undoing the file modifications caused by the merge is about assimple as you might hope. git revert -m 1 SHA
.(Obviously replace 'SHA' with the reference you want to revert;-m 1
will revert changes from all butthe first parent, which is almost always what you want.)Unfortunately, this is just the tip of the iceberg. The problem is,what happens months later, long after you have exiled this problemfrom your memory, when you try again to merge these branches (or anyother branches they have been merged into)? Because git has ittracked in history that a merge occurred, it is not going to attemptto remerge what it has already merged, and even worse, if you mergefrom the branch where you did the revert you will undo thechanges on the branch where they were made. (Imagine you revert apremature merge of a long-lived topic branch into master and latermerge master into the topic branch to get other changes for testing.)
One option is actually to do this reverse merge immediately,annihilating any changes before the bad merge, and then to 'revert therevert' to restore them. This leaves the changes removed from thebranch you mistakenly merged to, but present on their originalbranch, and allows merges in either direction without loss. Thisis the simplest option, and in many cases, can be the best.
Reworking the last commit
If you want to reorder commits, split them, merge them together, orotherwise perfect the commits, you shouldexplore PostProduction Editing Using Git.
Moving a commit from one branch to another
So, you have a commit which is in the wrong place and you want tomove it from one branch to another. In order to do this, you willneed to know the SHA of the first and last commit (in a continuousseries of commits) you want to move (those values are the same if youare moving only one commit), the name of the branch you are moving thecommit from, and the name of the branch you are moving the commit to.In the example below, I will name these four values $first, $last,$source, and $destination (respectively). Additionally, you will needto use a noncebranch as a placeholder. I will call the nonce branch 'nonce' in thefollowing example. However, you may use any branch name that is notcurrently in use. You can delete it immediately after you aredone.
Remember that when you substitute $first in the command above, leavethe '^' alone, it is literal.
Use gitk --all --date-order
to check tomake sure the move looks correct (pretending that nonce is thedestination branch). Please check very carefully if you were tryingto move a merge, it may have been recreated improperly. Ifyou don't like the result, you may delete the nonce branch(git branch -D nonce
) and try again.
However, if everything looks good, we can move the actualdestination branch pointer to where nonce is:
If you double-checked with gitk --all--date-order
, you would see that the destination branch lookscorrect. However, the commits are still on the source branch as well.We can get rid of those now:
Using gitk --all --date-order
one lasttime, you should now see that the commits on the source branch havegone away. You have successfully moved the commits. Please check verycarefully if merges occurred after the commits which were deleted.They may have been recreated incorrectly. If so you caneither undo thedelete or try to delete the bad merge and try to recreate itmanually, or create a fake (--ours) merge from the same SHA so thatgit is aware that the merge occurred.
Updating the last commit's contents or commit message
Php code generator. If you want to do something more sophisticated that what '--amend'allows, please investigate reworking thelast commit.
Do you want to remove an entire commit?
Removing an entire commit
Do you want to remove/change/rename a particular file/directory from all commits during all of git's history
Changing all commits during all of git's history
Use The BFG to remove unwanted data, like big files or passwords,from Git repository history.
The BFG is a simpler,faster alternative to git filter-branch
,specifically designed for cleansing bad data out of your Git repositoryhistory - it operates over all branches and tags in your project topurge data you don't want retained anywhere. Someexamples:
Remove all blobs bigger than 1 megabyte (to make your repo take up less space):
Replace all passwords listed in a file with ***REMOVED***
wherever they occur in your repository :
Arbitrarily changing all commits during all of git's history
git filter-branch
is a powerful, complexcommand that allows you to perform arbitary scriptable operations on allcommits in git repository history. This flexibility can make it quite slowon big repos, and makes using the command quite difficult, so I will simplypoint you at the manual pageand remind youthat bestpractice is to always use '--tag-name-filter cat ----all'
unless you are really sure you know what you aredoing.
BTW, this is the one command I referred to earlier which willupdate all tags and branches, at least if you use the best practicearguments.
Is a merge commit involved?
Changing a single commit involving only simple commits
You will be dumped in an editor with a bunch of lines starting withpick. The oldest commit, the one you are probably interested inchanging, is first. You will want to change the 'pick' to 'reword' or'edit', or perhaps even 'squash' depending on what your goal is.Please read the manual pagefor more information. A documenton Post-ProductionEditing using Git goes through much of the major uses of gitrebase is some detail. The use case is a little different, but thefundamental techniques are not.
When using 'edit', to change contents or author, when you aredumped into the shell to make your change, well make yourchange, git add
as normal, and thenrun git commit --amend
(including changingthe author information with --author). When you are satisfied, youshould run git rebase --continue
Changing a single commit involving a merge
Oh dear. This is going to get a little complicated. It should allwork out, though. You will need to usea nonce branch as aplaceholder. I will call the nonce branch 'nonce' in the followingexample. However, you may use any branch name that is not currentlyin use. You can delete it immediately after you are done.
Identify the SHA of the commit you wish to modify.
You can do this using
gitk --date-order
or usinggit log --graph --decorate--oneline
You are looking for the 40 character SHA-1 hash ID(or the 7 character abbreviation). Yes, if you know the '^' or'~' shortcuts you may use those.Remember the name of the branch you are currently on
The line with a star on it in the
gitbranch
output is the branch you are currently on. I will use'$master' in this example, but substitute your branch name for'$master' in the following commands.Create and checkout a nonce branch pointing at that commit.
Obviously replace 'SHA' with the reference you want to modify.
Modify the commit
You need to get the index into the correct state you wish thecommit to reflect. If you are changing the commit message only, youneed do nothing. If you are changing the file contents, typically youwould modify the working directory and use
gitadd
as normal.Note if you wish to restore a file to a known good state, you canuse
git checkout GOODSHA --path/to/filename
.Once the index is in the correct state, then you canrun
git commit --amend
to update the lastcommit. Yes, you can use '-a' if you want to avoidthegit add
suggested in the previousparagraph.If the commit you are updating is a merge commit, ensure that the logmessage reflects that.
Put the remaining commits after the new one you just created
Remembering to substitute the correct branch name for $master
Validate that the topology is still good
If some of the commits after the commit you changed are mergecommits, please be warned. It is possiblethat
git rebase -p
will be unable toproperly recreate them. Please inspect the resulting mergetopologygitk --date-order HEAD ORIG_HEAD
to ensure that git did want you wanted. If it did not, there is notreally any automated recourse. You can reset back to the commitbefore the SHA you want to get rid of, and then cherry-pick the normalcommits and manually re-merge the 'bad' merges. Or you can justsuffer with the inappropriate topology (perhaps creating fakemergesgit merge --ours otherbranch
sothat subsequent development work on those branches will be properlymerged in with the correct merge-base).Delete the nonce branch
You don't need it. It was just there to communicate an SHA betweentwo steps in the above process.
git branch -dnonce
Can you make a positive commit to fix the problem and what is the fix class?
Rewritingpublic history is a bad idea. It requires everyone else to dospecial things and you must publicly announce your failure. Ideallyyou will create either a commit to just fix the problem, or anew git revert
commit to create a newcommit which undoes what the commit target of the revert did.
Making a new commit to fix an old commit
Making a new commit to restore a file deleted earlier
Reverting an old simple pushed commit
Reverting a merge commit
Oh dear. This is going to get complicated.
To create an positive commit to remove the effects of a mergecommit, you must first identify the SHA of the commit you want torevert. Dazn canada reviews. You can do this using gitk--date-order
or using git log --graph--decorate --oneline
You are looking for the 40 character SHA-1hash ID (or the 7 character abbreviation). Yes, if you know the'^' or '~' shortcuts you may use those.
Git Stash Github Desktop Download
Undoing the file modifications caused by the merge is about assimple as you might hope. git revert -m 1 SHA
.(Obviously replace 'SHA' with the reference you want to revert;-m 1
will revert changes from all butthe first parent, which is almost always what you want.)Unfortunately, this is just the tip of the iceberg. The problem is,what happens months later, long after you have exiled this problemfrom your memory, when you try again to merge these branches (or anyother branches they have been merged into)? Because git has ittracked in history that a merge occurred, it is not going to attemptto remerge what it has already merged, and even worse, if you mergefrom the branch where you did the revert you will undo thechanges on the branch where they were made. (Imagine you revert apremature merge of a long-lived topic branch into master and latermerge master into the topic branch to get other changes for testing.)
One option is actually to do this reverse merge immediately,annihilating any changes before the bad merge, and then to 'revert therevert' to restore them. This leaves the changes removed from thebranch you mistakenly merged to, but present on their originalbranch, and allows merges in either direction without loss. Thisis the simplest option, and in many cases, can be the best.
A disadvantage of this approach is that gitblame
output is not as useful (all the changes will beattributed to the revert of the revert) and gitbisect
is similarly impaired. Another disadvantage is thatyou must merge all current changes in the target of the bad merge backinto the source; if your development style is to keep branches clean,this may be undesirable, and if you rebase your branches (e.g. withgit pull --rebase
), it could causecomplications unless you are careful to use gitrebase -p
to preserve merges.
Sony alpha a58 shutter county. In the following example please replace $destination with the nameof the branch that was the destination of the bad merge, $sourcewith the name of the branch that was the source of the bad merge,and $sha with the SHA-1 hash ID of the bad merge itself.
Another option is to abandon the branch you merged from, recreateit from the previous merge-base with the commits since then rebased orcherry-picked over, and use the recreated branch from now on. Thenthe new branch is unrelated and will merge properly. Of course, ifyou have pushed the donor branch you cannot use the same name (thatwould be rewriting public history and is bad) so everyone needs toremember to use the new branch. Hopefully you have something likegitolite where you can closethe old branch name.
This approach has the advantage that the recreated donor branchwill have cleaner history, but especially if there have been manycommits (and especially merges) to the branch, it can be a lot of work.At this time, I will not walk you through the process of recreatingthe donor branch. Given sufficient demand I can try to add that.However, if you look at howto/revert-a-faulty-merge.txt(also shipped as part of the git distribution) it will provide more wordsthan you can shake a stick at.
Stash App Github
Rewriting an old branch with a new branch with a new commit
I am a bad person and must rewrite published history
Proceed with fixing the old commit.
I have lost some commits I know I made
Undoing the last few git operations affecting HEAD/my branch's tip
Recovering from a borked/stupid/moribund merge
Recovering from a borked/stupid/moribund rebase
Disclaimer
Copyright
I would appreciate changes being sent back to me, being notified ifthis is used or highlighted in some special way, and links beingmaintained back to the authoritative source. Thanks.
Git Stash Github Desktop Version
Thanks
Comments
Usethe github issue tracker or discuss with SethRobertson (andothers) on #git
Line eater fodder
Because of my heavy use of anchors for navigation, and the utter lackof flexibility in the markup language this document is written in, itis important that the document be long enough at the bottom tocomplete fill your screen so that the item your link directed you tois at the top of the page.
Hopefully that should do it.