使用 repo sync
命令来同步远端服务器的 Android 代码,若是本地修改了代码但尚未 commit,会提示没法 sync:android
error: android/frameworks/base/: contains uncommitted changes
此时,能够使用 git reset
命令丢弃本地修改,而后再执行 repo sync
来同步代码。git
若是想要不丢失本地修改,强制同步远端服务器代码,能够加上 -d
选项,repo sync -d
命令会将 HEAD 强制指向 repo manifest 版本,而忽略本地的改动。bash
查看 repo help sync 的帮助信息,对 -d 选项的说明以下:服务器
-d, --detach
detach projects back to manifest revision
注意:加上 -d
选项只表示忽略本地改动,能够强制同步远端服务器的代码,可是本地修改的文件仍是保持改动不变,不会强制覆盖掉本地修改。并且同步以后,本地的分支指向会发生变化,再也不指向原来的分支。具体举例以下。ide
1.下面是执行 repo sync -d
以前的分支信息:测试
$ git branch * curent_branch_xxx
2.下面是执行 repo sync -d
以后的分支信息:this
$ git branch * (detached from 715faf5) curent_branch_xxx
即,从远端服务器同步的代码,是同步到跟踪远端服务器的分支,尚未从 git 仓库把代码 checkout 到本地,而当前本地修改的代码处在未命名分支下,是不一样的分支,互不干扰,才能在不丢弃本地修改的状况下,强制同步远端服务器代码。code
3.执行 git status
命令,能够看到本地仍是有修改过且尚未 commit 的文件,同步远端服务器代码后,并不会强制覆盖本地文件的修改:xml
$ git status HEAD detached at 715faf5 Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: vendor/chioverride/default/g_pipelines.h modified: vendor/topology/g_usecase.xml
即,若是想要丢弃本地修改、让本地代码跟同步后的 git 仓库代码一致,repo sync -d
命令达不到这个效果。ip
另外,repo sync 有一个 --force-sync
选项,具体说明以下:
--force-sync
overwrite an existing git directory if it needs to point to a different object directory. WARNING: this may cause loss of data
从说明来看,像是能够强制同步,且可能丢失本地改动。可是实际测试发现,这个选项并不能强制覆盖本地的改动。若是本地文件发生改动,加上这个选项也是会 sync 报错:
$ repo sync --force-sync . Fetching project tools/ error: tools/: contains uncommitted changes
同时提供 -d
和 --force-sync
两个选项,仍是不能强制覆盖本地修改。
目前没有找到 repo sync
命令能够强制覆盖本地修改的选项。