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 (ie 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.


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.


在这里输入图像描述

According to the IntelliJ IDEA documnetatition:

Update Type

  • Merge : choose this option to have the merge strategy applied. The result is identical with that of running git fetch ; git merge git fetch ; git merge or git pull --no-rebase .
  • Rebase : choose this option to have the rebase strategy applied. The result is identical with that of running git fetch ; git rebase git fetch ; git rebase or git pull --rebase .
  • Branch Default : choose this option to have the default command for the branch applied. The default command is specified in the branch.<name> section of the .git/config configuration file.
  • Clean working tree before update

    In this area, specify the method to save your changes while cleaning your working tree before update. The changes will be restored after the update is completed. The available options are:

  • Using Stash : choose this option to have the changes saved in a Git stash, so you can apply patches with stashed changed even outside IntelliJ IDEA, because they are generated by Git itself. Using
  • Shelve : choose this option to have the changes saved on a shelf. Shelving is a IntelliJ IDEA internal operation, patches generated from shelved changes are normally applied (unshelved) inside IntelliJ IDEA. Applying shelved changes outside IntelliJ IDEA is also possible but requires additional steps.

  • I couldn't find the answer to this question (ie the work-flow) in any of Google's documents... so here's my practical experience using Android Studio and Git completely from a UI.

    (I vomit at the thought of switching between command line and IDE - it means the IDE is lacking!)

  • Stash your changes with: Right Click Project -> Git -> Repository -> Stash Changes. Give it a name.
  • Pull updates that your colleague did with: Right Click Project -> Git -> Repository -> Pull
  • Merge back your code changes with: Right Click Project -> Git -> Repository -> UnStash Changes -> Apply Stash
  • You will then see a "Files Merged with Conflicts" UI. This is where you select a file and selectively merge.
  • WARNING

    The manual merge "Merge Revisions" UI is TERRIBLE . Once you try it, you'll see what I mean. Good luck trying to get "Synchronize Scrolling" to actually work. I sincerely hope this UI is addressed within the first few weeks of 2015.

    链接地址: http://www.djcxy.com/p/48942.html

    上一篇: 在GitHub上执行请求时避免不需要的合并提交和其他提交

    下一篇: Android Studio更新项目:合并与重建vs分支默认