Android Studio 更新项目:Merge vs Rebase vs Branch Default
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24393148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio Update Project: Merge vs Rebase vs Branch Default
提问by Kurt Wagner
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 应用程序)。如果有人推送到 master 分支并且您想拉入新的 master 以便它不会覆盖您仍在工作并且尚未提交并推送到 master 的工作,那么更新项目/拉取的最佳选择是什么?单击“更新项目”时,Android Studio 会列出“合并”、“变基”和“分支默认值”。从听起来像是,我想做“重新定位”(然后是“合并”?),但我不完全确定。
采纳答案by Bryan Herbst
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 changesto 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.
成功拉取后,您可以执行 agit stash apply
重新应用拉取前所做的更改。
Merging and rebasing
合并和变基
Stashing your changes only works if you only have uncommittedchanges. If at some point you committed but didn't push you will need to either rebase or merge.
只有当您只有未提交的更改时,才能存储您的更改。如果在某些时候您提交了但没有推送,您将需要重新设置或合并。
This StackOverflow posthas some great information on the differences.
这个 StackOverflow 帖子有一些关于差异的重要信息。
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.
同样,在您的情况下,您不需要合并或变基。简单地藏起来,拉,然后应用藏起来,一切都应该是好的。
回答by Volodymyr
According to the IntelliJ IDEA documentation:
根据 IntelliJ IDEA文档:
Update Type
更新类型
- Merge: choose this option to have the merge strategy applied. The result is identical with that of running
git fetch ; git merge
orgit 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
orgit 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 fetch ; git merge
或的结果相同git pull --no-rebase
。 - 调整基线:选择此选项,应用了重订战略。结果与运行
git fetch ; git rebase
或的结果相同git pull --rebase
。 - 分支默认:选择此选项以应用分支的默认命令。默认命令
branch.<name>
在.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 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.
- 使用 Stash:选择此选项将更改保存在 Git 存储中,因此即使在 IntelliJ IDEA 之外,您也可以应用已存储更改的补丁,因为它们是由 Git 本身生成的。
- 使用搁置:选择此选项可将更改保存在搁置上。搁置是 IntelliJ IDEA 内部操作,从搁置更改生成的补丁通常在 IntelliJ IDEA 中应用(未搁置)。在 IntelliJ IDEA 之外应用搁置的更改也是可能的,但需要额外的步骤。
回答by Someone Somewhere
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!)
- 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.
- 使用以下方法存储更改:右键单击项目 -> Git -> 存储库 -> 存储更改。给它一个名字。
- 拉取您同事所做的更新:右键单击项目 -> Git -> 存储库 -> 拉取
- 合并您的代码更改:右键单击 Project -> Git -> Repository -> UnStash Changes -> Apply Stash
- 然后,您将看到“与冲突合并的文件”用户界面。这是您选择文件并有选择地合并的地方。
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.
手动合并“合并修订”用户界面非常糟糕。一旦你尝试过,你就会明白我的意思。祝你好运,让“同步滚动”真正起作用。我真诚地希望这个用户界面能在 2015 年的前几周内得到解决。
回答by yoAlex5
According to documentation:
根据文档:
Merge: select this option to perform mergeduring the update. This is equivalent to running
git fetch
and thengit merge
, orgit pull --no-rebase
.
Rebase: select this option to perform rebaseduring the update. This is equivalent to runninggit fetch
and thengit rebase
, or `git pull --rebase (all local commits will be put on top of the updated upstream head).
Branch Default: select this option if you want to apply different update strategies for different branches. You can specify the default update type for each branch in thebranch.<name>
section of the.git/config
configuration file.
合并:选择此选项可在更新期间执行合并。这相当于运行
git fetch
然后git merge
, 或git pull --no-rebase
。
Rebase:选择此选项可在更新期间执行rebase。这相当于运行git fetch
然后运行git rebase
,或者`git pull --rebase(所有本地提交都将放在更新的上游头部之上)。
Branch Default:如果要为不同的分支应用不同的更新策略,请选择此选项。您可以branch.<name>
在.git/config
配置文件的部分中为每个分支指定默认更新类型。
Read more here
在这里阅读更多
回答by Deepak Ror
Update Git project with android studio terminal
使用 android studio 终端更新 Git 项目
- git add .
- git commit -m "anything"
- git push origin master
- git 添加。
- git commit -m “任何东西”
- git push origin master
This is what I was wanting to find the answer from your post. So that's why I writing this answer.
这就是我想从你的帖子中找到答案的。所以这就是我写这个答案的原因。