Lolly
Lolly

Reputation: 36422

git stash and git pull

I am new to Git and I am using EGit eclipse plugin to commit.

I modified few files and I stashed the changes, then I did git pull in command line which pulled up all the latest commits. Then I did Apply stashed changes from EGit. Now it applied my changes and the changes which pulled from last commit of stashed files went out. I am not sure why it didn't ask me about merge conflicts and overwrote my changes and lost previous commits changes.

How to get those changes?

Upvotes: 129

Views: 204742

Answers (3)

leonheess
leonheess

Reputation: 21391

Instead use:

git pull --autostash

If you want that behavior to be the default:

git config --global pull.rebase true
git config --global rebase.autostash true

Upvotes: 31

Petur Subev
Petur Subev

Reputation: 20203

That's the first thing to do when you edit your .gitconfig

[pull]
  autostash = true
; and also
[rebase]
  autostash = true
[merge]
  autostash = true

Upvotes: 4

yilmazhuseyin
yilmazhuseyin

Reputation: 6612

When you have changes on your working copy, from command line do:

git stash 

This will stash your changes and clear your status report

git pull

This will pull changes from upstream branch. Make sure it says fast-forward in the report. If it doesn't, you are probably doing an unintended merge

git stash pop

This will apply stashed changes back to working copy and remove the changes from stash unless you have conflicts. In the case of conflict, they will stay in stash so you can start over if needed.

if you need to see what is in your stash

git stash list

Upvotes: 297

Related Questions