Android Source repo 同步最新更改?

发布于 2024-10-10 10:53:57 字数 353 浏览 2 评论 0原文

我有一个 Android 源代码树的工作副本,我用它来进行编译。我想同步存储库中的最新更改(他们所做的任何新事情),但我收到一个错误,

"You have local changes to 'kernel'; cannot switch branches."
"You have local changes to 'products/common.mk; cannot switch branches."

然后我在我认为结束时出现了 2 个错误(似乎在之后又做了一行树同步)那)。

所以,我的问题是,如何在我本地更改的内容之上同步他们的更改? 我无法提交更改,因为我不是该项目的贡献者,我想将更改保留在本地。

I have a working copy of the Android source tree that I have used to compile from. I want to sync the latest changes from the repo (any new things they have done) but I get an error that

"You have local changes to 'kernel'; cannot switch branches."
"You have local changes to 'products/common.mk; cannot switch branches."

then I get presented 2 errors at what I assume is the end (it seems to have done one more line of tree syncing after that).

So, my question is, how do I sync their changes on top of things I have changed locally?
I cannot commit a change because I am not a contributor to the project, I want to keep my changes local.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

奶茶白久 2024-10-17 10:53:57

你的问题实际上是git中常见的情况——使用git进行本地化更改。

当你使用 git pull 时,你只能得到本地 git 镜像和远程 git 服务器之间的差异。每当您进行本地更改时,您都可以发出 git diff 来查看差异。因此,对于您来说,您的步骤应该是:

  1. git diff > mydiff.patch 获取您所做更改的补丁差异。
  2. git checkout -f 以恢复到本地化更改之前的原始图像。
  3. git pull 从远程服务器进行完整的 git 更新。这也是reposync可以发挥作用的地方 - reposync基本上下降到一系列git命令(通过ps -ef查看)
  4. 然后您通过 patch -p1 --dry-run patch -p1 --dry-run 再次重新应用本地化更改mydiff.patch 来测试重新应用。如果成功,请通过以下方式进行真正的修补:

    补丁-p1 < mydiff.补丁
    

    如果不成功,这只意味着您的更改与其他人已提交的远程服务器端所做的某些更改发生冲突,此时您必须再次手动重做更改 - 乏味但别无选择。

请注意:git 可以应用于您看到 .git 目录的每个目录,并且 git 命令仅在该目录级别生效。如果您在具有 .git 子目录的不同目录中进行了多次更改,那么您必须为每个目录执行 git diffgit checkout -f那些目录。

例如,在进行reposync更新时,我得到:

Fetching projects: 100% (172/172), done.  
Syncing work tree:   2% (4/171)  error: You have local changes to 'core/base_rules.mk'; cannot switch branches.
Syncing work tree:   3% (6/171)  error: You have local changes to 'tools/dx-tests/Android.mk'; cannot switch branches.
Syncing work tree: 100% (171/171), done.  

external/dbus/: discarding 43 commits
error: build/: platform/build checkout 0683a77348f2a0a529a8e2bcfdf4b6dc6b4c5f5b 
error: cts/: platform/cts checkout a3779fa378345bfd8699e91de46b29563be4beb2 

向下遍历,我发现在cts目录下是一个.git,所以< code>cd cts 和 git diff 给出了差异。

上述方案非常简单,因为始终只有一个分支 - 主分支,并且您的更改始终位于其之上。

或者,您必须使用 gitbranch 构建您自己的分支,然后使用 git merge 将您的分支合并到默认的 master 分支(阅读 这个)。

合并命令为 git merge topic,其中 topic 是使用 gitbranch 创建的分支,用于容纳您的自定义更改。

总的来说,操作仍然与上面相同 - 如果master和你的分支在同一行修改同一个文件,或者你的修改发生在master之后,就会发生冲突。

Your question is actually a commonly encountered situation in git - making localized changes using git.

When you use git pull, you only get the diff between the local git image and the remote git server. whenever you make local changes, you can issue git diff to see the differences. So for you your steps should be:

  1. git diff > mydiff.patch to get a patch difference of the changes u have made.
  2. git checkout -f to revert back to the original image before your localized changes.
  3. git pull to do a full git update from remote server. this is where repo sync can come in as well - as repo sync drop to basically a sequence of git command (viewed via ps -ef)
  4. then you re-apply your localized changes again via patch -p1 --dry-run < mydiff.patch to test out the reapplication. If successful, do the real patching via:

    patch -p1 < mydiff.patch
    

    If not successful, it only means that your changes is conflicting with some changes done on the remote server side that others have committed, and this is where you have to manually redo your changes again - tedious but no choice.

Take note: git can be applied at each directory where you see a .git directory, and the git command only take effect at that directory level. If you have make multiple changes in different directories with .git subdirectory, then you have do a git diff and git checkout -f for each of those directory.

For example, while doing a repo sync update I got:

Fetching projects: 100% (172/172), done.  
Syncing work tree:   2% (4/171)  error: You have local changes to 'core/base_rules.mk'; cannot switch branches.
Syncing work tree:   3% (6/171)  error: You have local changes to 'tools/dx-tests/Android.mk'; cannot switch branches.
Syncing work tree: 100% (171/171), done.  

external/dbus/: discarding 43 commits
error: build/: platform/build checkout 0683a77348f2a0a529a8e2bcfdf4b6dc6b4c5f5b 
error: cts/: platform/cts checkout a3779fa378345bfd8699e91de46b29563be4beb2 

Traversing downwards, I discovered that under the cts directory is a .git, so cd cts and git diff gives the difference.

The above scheme is simple enough, as there is always only one branch - the master branch, and your changes is always on top of that.

Alternatively you have to use git branch to build your own branch, and then git merge to merge your branch into the default master branch (read this).

The command for merging will be git merge topic, where topic is the branch created with git branch to house your customized changes.

Overall the operations are still the same as above - conflicts will occur if the master and your branch modify the same file at the same line, or your modification comes AFTER the master.

羁客 2024-10-17 10:53:57

虽然我没有太多使用 git ,并且我从建议消息中假设您正在访问 git 存储库,但我相信该工具只是拒绝覆盖您的本地更改..这是一个很好的选择事,是吗?我认为事情正在按照您希望的方式发生,除非您想在本地工作和最新的回购视图之间切换。

也许这个指南(关于SO) Git 初学者:权威的实用指南 可能会有所帮助。

While I've not used git much and I'm assuming from the advisory messages that you are accessing a git repo, I believe the tool is simply refusing to overwrite your local changes .. which is a good thing, yes? I think things are happening exactly as you wish them to happen, unless you'd like to flip between your local work and the latest repo view.

Perhaps this guide (on SO) Git for Beginners: The definitive practical guide may be some help.

梦里人 2024-10-17 10:53:57

您可以使用另一个分支进行更改...或尝试 git pull --rebase

You can use another branch for your changes... or try git pull --rebase

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文