如何正确管理Android源代码的更改?

时间:2013-05-03 21:39:31

标签: android git android-source repository cyanogenmod

假设我正在从源代码构建Android或CyanogenMod,并希望对其源代码进行更改。另外,我们假设我不想提交这些更改(例如,因为它们不完整或者是已经被拒绝的更改)。

管理它的最佳方法是什么?如何对我的“个人”更改进行适当的源代码控制,但同时能够使用repo sync以便我进行最新的更改?

我可以拥有本地分支(对于每个我做出更改的项目),并且只需在每次重新同步后从主分支合并到我的本地分支吗?

4 个答案:

答案 0 :(得分:0)

当您运行“repo sync”时,实际发生的是每个git存储库都在新的上游进行重新定位。如果您在特定的git存储库中没有任何本地补丁,那么这是一个简单的快进。如果你确实有一些补丁而且上游也有(你的分支和上游分支有分歧),repo会尝试自动rebase。

因此,假设您在上游代码之上有一个补丁,并且自您应用该补丁以来,上游已经有了一些新的命令。当您运行repo sync时,repo将尝试在上游之上重新设置代码。如果自动rebase失败,repo将抛出一条错误消息,通知您应该手动修复补丁。

总结一下:您可以在要修改的每个项目中创建一个分支,将提交存储在该分支上。回购同步将自动修改您的补丁(除非它失败,然后您必须手动应用它们。)

答案 1 :(得分:0)

您需要使用repo start命令创建一个跟踪远程repo分支的主题分支。或者您需要使用git branch命令的--track选项手动创建具有远程跟踪分支的本地分支。使用git branch命令的--set-upstream选项将跟踪分支添加到现有本地分支。

正确设置跟踪分支后,repo sync命令将快速转发并重新应用本地修补程序,如Anton Cherkashyn在其答案中所述。

答案 2 :(得分:0)

将gerrit与repo和git结合使用。

答案 3 :(得分:0)

这似乎对我有用。

首先提一些设置

# cd to root of source tree
repo start MyBranch       # Create working branch for all projects
repo checkout MyBranch    # switches all projects to use MyBranch

时间过去了,精彩的编辑和承诺(在MyBranch中),工作分支很干净。现在想要上游改变......

# Current active branch is "MyBranch"
# The following sync -d as per repo docs:
#     -d: switch specified projects back to the manifest revision.
#      Helpful if the project is currently on a topic branch,
#      but the manifest revision is temporarily needed.
# In other words, it automatically syncs default manifest's upstream
repo sync -d -j12

# Active branch may be "MyBranch" or possibly a detached head or whatever.
# So, if necessary, switch back to MyBranch
# - I usually do this just to make sure all projects are in MyBranch
# - NOTE: If a new project appears it won't have MyBranch
repo checkout MyBranch

# Now we're in MyBranch. Its "upstream" is our local master so sync it.
# - This is usually rather quick
repo sync

“repo sync -d”可能没有必要,但就我所见,并没有造成任何问题。此外,它会在本地拉出主代码行,以使其与手持差异等同步。

也许MyBranch内部的“repo sync”也是如此。但是,当我省略“repo sync -d”步骤时,我似乎没有得到任何更新,只是在签出MyBranch时执行“repo sync”。 (虽然我的本地设置可能会以某种方式搞砸了)

总结:

选项A:可能会工作

cd RootOfRepoSourceTree   # wherever you have it
repo checkout MyBranch
repo sync

选项B:一直为我工作

cd RootOfRepoSourceTree   # wherever you have it
repo sync -d -j12
repo checkout MyBranch
repo sync
相关问题