top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Whats does mean of GIT stash?How to recover stashed uncommitted changes?

+1 vote
516 views
Whats does mean of GIT stash?How to recover stashed uncommitted changes?
posted Aug 27, 2015 by Amit Kumar Pandey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the git stash command.

answer Aug 28, 2015 by Avinash Ks
Similar Questions
0 votes

After switching from svn/hg to git and getting some experience, I feel I'm ready to figure out which questions aren't too obvious. My feeling is the current question isn't.

Today I was hacking away, only to discover that I was really working on too much stuff at once. I wanted to stash away a sub-set of my changes, and leave the rest to focus on first. So I did a 'git stash --patch', selected the patches I wanted to move away for now. Only to discover that I stashed away 2 patches too many .... Bummer.

Alas: I kind of hoped I could do something like 'git stash apply --patch stash@{1}'...... but that didn't quite work: I just got the full stash applied on top of the working directory (to be verbose: this was done after stashing the remaining patches).
I hope my situation was explained clearly enough. My question is not about how to recover. That's easy by redoing the original stash command, but properly this time. My question is more about learning something more about git, in case I end up in the same, or a similar situation in the future:
* is there a way to force 'git stash --patch' to create a separate stash for each patch that I select? This would make it possible to apply each patch again afterwards, and would have been a perfect solution in my case as well
* otherwise, is there a way to achieve the result I had hoped for when running 'git stash apply --patch', namely to selectively apply hunks

In case the answer to both of these is 'No', what would be the proper way and/or place to suggest such a feature?

+1 vote

Perhaps my git workflow is wrong.

I have committed numerous times in order to complete a task, but when the code is to be reviewed, Id like to show a non-contiguous view of my changes, which do not include the commits other developers have made. Is this possible?

Or should I be creating a branch and showing the differences from the master and my branch when it comes to a code review?

+2 votes

One practice of using git to have one feature per branch.

Let's say a developer has worked on many small features in many branches. Then he sends one pull request to the central (not controlled by him) for each feature he has developed. While he is waiting for all the features be merged into the central repository, he needs to use all these feature locally.

To do so, he may need to merge the changes in these branches to his local master branch. But this can be tedious when he has many branches.

Is there a way to somehow setup a branch so whenever something is committed to the branch, the changes will also be simultaneously committed to the local master branch? By this way, the develop can avoid having to merge changes from many branches.

+1 vote

I'm having difficulty understanding how I should use git when I have multiple independent changes in a project. I have a local git repository for various windows & linux machines and I work on different parts of the project on different machines. The situation I have is that I am part way through some changes on one part of the project. On the same machine, I have made some quick changes to another part of the project and I would like to commit those changes and push them to the origin, _without_ having to commit the other changes that I am still working on. Surprisingly, I don't seem to be able to do this with git.

  • I can commit the completed changes without committing the uncompleted changes ok.
  • If I try to push the changes, git complains that I have unstaged changes and I should do a local merge.
  • I can't even seem do a local merge without pulling other changes from the origin.

So now I've ended up with part-finished changes on the master. Not what I wanted! What should I be doing here?

+3 votes

I opened a file and wrote a piece of code.
When I ran $git diff
it is showing the differences what I did.
Can I get back the file (version) which is in remote branch ?
Is there any command ?

...