Android Studio更新项目:Merge vs Rebase vs Branch Default

时间:2021-11-12 20:49:31

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.

抱歉,如果这看起来多余,因为我知道有很多关于Merge和Rebase的问题,但似乎也没有任何关于“分支默认”的问题。

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.

您将获得一个案例,您可以同时处理多个人(即Android Studio中的Android应用程序)。如果有人推送到主分支并且您想要引入新主服务器以便它不会覆盖您仍在处理并且尚未提交并推送到主服务器的工作,那么更新项目/拉动的最佳选项是什么?单击“更新项目”时,Android Studio会列出“合并”“重新生成”和“分支默认”。听起来,我想做'Rebase'(后面是'Merge'?),但我不完全确定。

3 个解决方案

#1


31  

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.

运行git stash来存储您的更改。然后,您应该能够毫无问题地提取更改。

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

成功拔出后,您可以执行git stash apply以重新应用您在拉动之前所做的更改。

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.

仅当您只有未提交的更改时,才会保留您的更改。如果在某些时候你提交但没有推动你将需要rebase或merge。

This * 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.

一般来说,合并更容易,但有些人认为合并提交会“污染”git历史记录。

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.

同样,在您的情况下,您不需要合并或变基。只需藏匿,拉动,然后应用藏匿处,它应该都很好。

#2


10  

Android Studio更新项目:Merge vs Rebase vs Branch Default

According to the IntelliJ IDEA documnetatition:

根据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 or git pull --no-rebase.
  • 合并:选择此选项以应用合并策略。结果与运行git fetch的结果相同; git merge或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 or git pull --rebase.
  • Rebase:选择此选项以应用rebase策略。结果与运行git fetch的结果相同; git rebase或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.
  • 分支默认值:选择此选项可以应用分支的默认命令。默认命令在.git / config配置文件的分支。 部分中指定。

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
  • 使用Stash:选择此选项可以将更改保存在Git存储中,这样即使在IntelliJ IDEA之外也可以应用已更改的修补程序,因为它们是由Git本身生成的。运用
  • 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.
  • 搁架:选择此选项可将更改保存在搁板上。搁置是一种IntelliJ IDEA内部操作,通常在搁置的更改中生成的补丁(IntelliK IDEA)内部应用(未加载)。在IntelliJ IDEA之外应用搁置的更改也是可能的,但需要额外的步骤。

#3


5  

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

我无法在Google的任何文档中找到这个问题的答案(即工作流程)...所以这是我在UI中完全使用Android Studio和Git的实践经验。

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

(我呕吐在命令行和IDE之间切换的想法 - 这意味着IDE缺乏!)

  1. Stash your changes with: Right Click Project -> Git -> Repository -> Stash Changes. Give it a name.
  2. 使用以下方法存储您的更改:右键单击项目 - > Git - >存储库 - >存储更改。给它起个名字。
  3. Pull updates that your colleague did with: Right Click Project -> Git -> Repository -> Pull
  4. 拉取您的同事所做的更新:右键单击项目 - > Git - >存储库 - >拉
  5. Merge back your code changes with: Right Click Project -> Git -> Repository -> UnStash Changes -> Apply Stash
  6. 将代码更改合并为:右键单击Project - > Git - > Repository - > UnStash Changes - > Apply Stash
  7. You will then see a "Files Merged with Conflicts" UI. This is where you select a file and selectively merge.
  8. 然后,您将看到“与冲突合并的文件”UI。这是您选择文件并有选择地合并的地方。

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.

手动合并“合并修订”UI是可怕的。一旦你尝试了,你就会明白我的意思。祝你试图让“同步滚动”真正起作用。我真诚地希望在2015年的前几周内解决这个用户界面问题。

#1


31  

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.

运行git stash来存储您的更改。然后,您应该能够毫无问题地提取更改。

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

成功拔出后,您可以执行git stash apply以重新应用您在拉动之前所做的更改。

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.

仅当您只有未提交的更改时,才会保留您的更改。如果在某些时候你提交但没有推动你将需要rebase或merge。

This * 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.

一般来说,合并更容易,但有些人认为合并提交会“污染”git历史记录。

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.

同样,在您的情况下,您不需要合并或变基。只需藏匿,拉动,然后应用藏匿处,它应该都很好。

#2


10  

Android Studio更新项目:Merge vs Rebase vs Branch Default

According to the IntelliJ IDEA documnetatition:

根据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 or git pull --no-rebase.
  • 合并:选择此选项以应用合并策略。结果与运行git fetch的结果相同; git merge或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 or git pull --rebase.
  • Rebase:选择此选项以应用rebase策略。结果与运行git fetch的结果相同; git rebase或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.
  • 分支默认值:选择此选项可以应用分支的默认命令。默认命令在.git / config配置文件的分支。 部分中指定。

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
  • 使用Stash:选择此选项可以将更改保存在Git存储中,这样即使在IntelliJ IDEA之外也可以应用已更改的修补程序,因为它们是由Git本身生成的。运用
  • 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.
  • 搁架:选择此选项可将更改保存在搁板上。搁置是一种IntelliJ IDEA内部操作,通常在搁置的更改中生成的补丁(IntelliK IDEA)内部应用(未加载)。在IntelliJ IDEA之外应用搁置的更改也是可能的,但需要额外的步骤。

#3


5  

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

我无法在Google的任何文档中找到这个问题的答案(即工作流程)...所以这是我在UI中完全使用Android Studio和Git的实践经验。

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

(我呕吐在命令行和IDE之间切换的想法 - 这意味着IDE缺乏!)

  1. Stash your changes with: Right Click Project -> Git -> Repository -> Stash Changes. Give it a name.
  2. 使用以下方法存储您的更改:右键单击项目 - > Git - >存储库 - >存储更改。给它起个名字。
  3. Pull updates that your colleague did with: Right Click Project -> Git -> Repository -> Pull
  4. 拉取您的同事所做的更新:右键单击项目 - > Git - >存储库 - >拉
  5. Merge back your code changes with: Right Click Project -> Git -> Repository -> UnStash Changes -> Apply Stash
  6. 将代码更改合并为:右键单击Project - > Git - > Repository - > UnStash Changes - > Apply Stash
  7. You will then see a "Files Merged with Conflicts" UI. This is where you select a file and selectively merge.
  8. 然后,您将看到“与冲突合并的文件”UI。这是您选择文件并有选择地合并的地方。

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.

手动合并“合并修订”UI是可怕的。一旦你尝试了,你就会明白我的意思。祝你试图让“同步滚动”真正起作用。我真诚地希望在2015年的前几周内解决这个用户界面问题。