locoboy
locoboy

Reputation: 38940

I'm trying to get the last version of my code on git

I'm trying to get the last version of the master code on my local machine without deleting any current work that's being done in the later part of the tree. How do I accomplish this in git?

enter image description here

I want my local machine to have the code at the 'new items' version without deleting those changes that are happening in the master version above it.

Upvotes: 0

Views: 88

Answers (2)

sciritai
sciritai

Reputation: 3758

Use

git stash
git stash pop

to save and restore your working directory.

If you have some commits that are not pushed and will cause a merge conflict, use

git rebase

This will save any commits not yet pushed, fetch the latest code, apply it, and then put the saved commits on top of the newest commits. And you're done.

EDIT: If you want to avoid the merge conflicts with code already committed, then use

git reset --soft

That'll take all committed but not yet pushed code and put it back in the index. Then you can stash that, and pull from master.

Upvotes: 1

ma11hew28
ma11hew28

Reputation: 126357

Close any open editors that will complain if you change files out from under them.

Stash changes (in files Git is tracking) since the last commit:

git stash

Checkout the commit made before the last commit on the master branch:

git checkout master^

Done!

To get back to where you started:

git checkout master
git stash pop

Check out this awesome Git book.

Upvotes: 0

Related Questions