用Repo强制同步远程代码

来源:互联网 发布:问道手游秒公示软件 编辑:程序博客网 时间:2024/05/22 03:26

Android ROM开发经常使用repo sync。有时候有些project因为调试的原因做了一些改动,sync下来就和远程不同步了。
参考了repo的代码(.repo/repo/subcmds/sync.py)里有个参数:
p.add_option(‘-d’, ‘–detach’,
dest=’detach_head’, action=’store_true’,
help=’detach projects back to manifest revision’)
repo sync -d会将HEAD强制指向manifest的库,而忽略本地的改动。
所以比较安全的做法是
先确认本地改动没必要保存了,确认之前不妨用分支备份一下(git checkout -b backup_branch; git add -u; git commit)

或者用笨办法,直接用cp备份一下,然后:

repo sync -d
repo forall -c ‘git reset –hard’ # Remove all working directory (and staged) changes.
repo forall -c ‘git clean -f -d’ # Clean untracked files

强制与远程服务器同步,会删除对服务器文件的修改,但是不会删除添加到目录的新文件repo forall -c git reset --hard HEAD
删除新添加的文件repo forall -c git clean -xfd
原创粉丝点击