开发者

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 machi开发者_开发百科ne without deleting any current work that's being done in the later part of the tree. How do I accomplish this in git?

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

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜