Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
936 views
in Technique[技术] by (71.8m points)

git - Android Studio Update Project: Merge vs Rebase vs Branch Default

Apologies if this seems redundant as I know there are fair amount of questions regarding Merge vs Rebase, but there doesn't seem to be any that throw in 'Branch Default' as well.

You are given a case where you have multiple people working on something (i.e. an Android app in Android Studio) concurrently. What is the best option to update project/pull if someone pushes to the master branch and you want to pull in the new master such that it doesn't overwrite the work you are still working on and have yet to commit and push to master? Android Studio lists 'Merge' 'Rebase' and 'Branch Default' when clicking 'Update Project'. From what it sounds like, I would want to do 'Rebase' (followed by 'Merge'?), but I'm not entirely sure.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Stashing

The key here is that you have uncommitted work that you want to save. Before trying to merge anything in, you should stash your changes to save your uncommitted changes and clean your working directory.

Run git stash to stash your changes. You should then be able to pull the changes without any issues.

After you have successfully pulled, you can do a git stash apply to re-apply the changes you had made prior to the pull.

Merging and rebasing

Stashing your changes only works if you only have uncommitted changes. If at some point you committed but didn't push you will need to either rebase or merge.

This StackOverflow post has some great information on the differences.

In general, merging is easier, but some believe that it "pollutes" the git history with merge commits.

Rebasing requires additional work, but since you don't have a merge commit it will essentially make the merge invisible.

Again, in your case you shouldn't need to merge or rebase. Simply stash, pull, then apply the stash and it should all be good.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...