I am able to clone the Android source code by using the "repo" tool. However, what I want to do is clone the source code in a more minimal way than having an 11GB footprint. It seems to download things related to every Android device and every prior release. I tried thought I could reduce this by checking out a specific branch like this:
repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
However, what ends up happening is that I still get everything involved, just at a specific snapshot (understandable). But is there any way to limit the amount that is cloned?
The android source tree is made up of many separate git repositories, which are all managed by repo. You can't really reduce the amount of data that's downloaded for a given git repository.
However, you can only download a subset of the git repos that are available, using repo sync <project>. I.e. if you only wanted the frameworks/base package, you should be able to do repo sync frameworks/base, after doing the initial repo init.
If you are actually wanting to build the source though, you probably want the full thing.
You might be able to save a gig or two by removing the device repositories that you don't need. You can do this by editing <source>/.repo/manifest.xml and removing the repositories for the devices you don't want.
There are a number of things you can do. First, "repo sync" with a -c argument will limit the checked-out sandbox to only the "current" branch. The repo sync will not download material for other branches.
You can also edit the .repo/manifests/default.xml manifest. What I do is make a backup of it such as "default.bak" and then strip out the lines from the default.xml file I know I don't need. Because I'm not building on a Macintosh, I know I don't need any of the "darwin" tools, so I remove every line that contains "darwin". Then "repo sync" doesn't download any darwin projects or install the source code in the sandbox.
If you already synched a sandbox, and you want to trim its size, you can strip projects out as above, and then do "repo sync -c -l", and repo sync will only strip the directories that you just removed. The -l flag only does the local part of the sync, which means it only syncs the local git projects with your source tree. The network is not used. See the "-n" flag for the other half of a normal sync, which does the network sync to update the local git projects with the upstream repository.
To also remove the git backing object stores for the unwanted projects (which take up a lot of room) I use this:
for project in `diff ~/android/.repo/manifests/default.xml ~/android/.repo/manifests/default.bak | awk '{print $3}' | grep path | cut -f2 -d\"`; do rm -rf ~/android/.repo/projects/$project.git ; rm -rf ~/android/.repo/project-objects/$project.git ; done
This finds all the projects that are in your backup manifest, but have been removed from your active manifest, and removes the git projects and all the backing data for them. This recovers a lot of space.
If you remove too much, just recover the project line from your backup manifest, and add it back into your active manifest. Then, a repo sync will get your git projects and your sandbox straight again. You can test the build to see if you've removed too much by doing "mma -B -n" in your project directory. This will try to do a full dependency build on your target, forcing all the targets to build even if they don't need it, and it will do it as a dry run. If the build fails, you removed something your project needs.
You can also set up a local mirror sandbox, and create small, working, reference sandboxes from your mirror. The working sandboxes don't contain git object stores, but refer to the central ones in the mirror. Use "repo init -u ... --mirror" to set up the mirror, and "repo init --reference=~/android-mirror -u ..." to refer to the mirror. The -u flag in the latter allows a real upstream repository to be used as the authority, while the mirror reference is used as a local cache. Local mirrors also avoid the download quota that the AOSP project enforces, and they are faster to sync to.
Related
I apologize if some of my terminology is off, feel free to correct that as well.
If you use repo sync -c, you will only download the current branch for every project in the selected manifest. If you don't use -c you will download other branches for all projects. Is there a way to delete all other branches after you have already repo synced without -c? I was hoping for something like:
repo forall -c git [delete all branches except current],
but there doesn't seem to be a command like that in git. Can repo do this?
We have been using gerrit as our android source code repo. We usually use git bash
commands to do push ,pull and commit for working with gerrit.I want to how we can configure the android studio itself with gerrit so that i don't need to type in commands in git bash. I tried to change some settings in the Android studio in git version control option but that really didn't work.
One more thing is that whenever we do a commit through git commit command git creates (or something else i am sure as i am not very good at git commands and env) changeId: This is very important for pushing/amending the changes.How can i add changeId while i commit from studio.
Let me know if i am not very clear about my question , i will add more.
This is the image of my push Ui from studio where i can't see the origin HEAD :
Android Studio’s Git GUI should be able to do almost all the jobs through menus and buttons. The only annoying thing may be that you need to change the remote ref in the push menu from master or refs/heads/master to refs/for/master to create changes for review.
Change-Id is created by a hook commit-msg. As I know, it is under repo/hooks if you use Google’s REPO. The repositories cloned by repo sync have commit-msg deployed, so you don’t need to worry about it. But as for those repositories created by git clone or git init, you need to install it. Gerrit’s project page provides a clone command which includes scp that downloads and copies the hook automatically. If you clone through Android Studio, you could manually install it under .git/hooks/ for one repository, or copy it to $GITBASH/ming64(32)/share/git-core/template/hooks on Windows so that any new created repository will have it installed automatically.
So I'm fairly new to git, but I have basic knowledge of how it operates and I have been playing around with the Android source recently (more specifically LineageOS, but it doesn't really matter for my question).
Basically, I followed the Android and Lineage guides to setting up a build environment with Linux (Xubuntu 16.04 LTS), downloaded the source, got my phone's proprietary blobs and successfully built it. Next I began cherry-picking some features.
According to the Google documentation for AOSP, I should move to a project folder and do a "repo start BRANCH_NAME ." to create a topic branch, then make my changes, git add them and commit them. The thing is, I don't want to push these changes to anywhere. I am simply wanting to work locally, only pulling new changes while keeping my cherry picks. So I did a bunch of cherry picks and ran a build again, which was successful but one of the things I cherry picked is causing me an issue and I want to completely revert it.
I first did repo sync and moved to a project folder, when I did "git branch", it returned "* (no branch)" in green, and when I did "git status", it told me that I'm not currently on a branch and that the working directory is clean.
Now, since I created a topic branch in one of these projects and cherry picked a couple commits, git status tells me I am 2 commit aheads, so to remove them, I did "git reset --hard github/cm-14.1", which completed and I verified that the files were reverted back to their original state. I ran "repo prune" to get rid of the now unneeded topic branch, and when I run "git branch" again, it says "* (HEAD detached at 12f0903)" in green and when I run run "git status" it also says HEAD is detached at 12f0903 in red, but also tells me that there is nothing to commit and that my working directory is clean.
Finally, after all of that, if I just create a new branch now, status and branch return clean, normal output with no detached head message. Is there a way to get back to the very beginning state of not being in a branch and not having a detached head or am I totally confused and doing something wrong?
Is there a way to get back to the very beginning state of not being in a branch and not having a detached head
Simply checkout the SHA1 referenced by your current branch:
git checkout $(git rev-parse HEAD)
As already stated, being in a detached HEAD mode is not a big deal, unless you want to add new commit (in which case, creating a dedicated branch that you would push to a fork is a good idea)
The Android Lineage guide mention the command
repo init -u https://github.com/LineageOS/android.git -b cm-14.1
That means you can go back to the local branch cm-14.1 with
git reset --hard cm-14.1
I changed a drawable a png file after I edited with GIMP and added to Android Studio in res folder. On the emulator i can see it is changed. And i can see on bitbucket that is not changed although i send these commands
git add -A #I tried also git add -u and git add .
git commit -m "new button"
git push -u origin master
my git status says that everything is updated. I understand that the way git works does not detect that i changed the file. I remember i did it something in few months ago without using rm but I cannot remember which command I used
Try the --refresh and --force flags.
From the Git manual:
--refresh
Don’t add the file(s), but only refresh their stat() information in the index.
-f, --force
Allow adding otherwise ignored files.
Can confirm in my experience that changing the name of my image on my local site and then adding and pushing the changes to Git caused the image to then show up on git's live page servers.
Thanks for the tip #trocchietto!
I found a workaround, but I would not be happy to mark as answer. Just changed the name of the file, refactored the name, and added, committed and successfully pushed.
It works, but is not the command I launched few months ago
Let's say I'm building Android or CyanogenMod from source and want to make changes to its source. Also, let's assume I don't want to submit these changes (since they are incomplete or are changes that have already been rejected, for example).
What is the best way to manage that? How can I have proper source control of my "personal" changes, but at the same time be able to use repo sync so that I have the latest changes?
Can I have local branches (for each project I make changes) and simply merge from the master branch to my local branches after every repo sync?
When you run "repo sync" what actually happens is that each git repository is rebased on a new upstream. If you don't have any local patches in a specific git repository, it's a simple fast-forward. If you do have some patches and upstream does as well(your branch and upstream branch have diverged), repo will attempt an automatic rebase.
So lets say you have a patch on top of upstream code, and upstream has had some new comits since you applied that patch. When you run repo sync, repo will try to rebase your code on top of upstream. If the automatic rebase fails, repo will throw an error message letting you know that you should fix the patch manually.
To sum it up: You can create a branch in each project you want to modify, store your commits on that branch. Repo sync will automatically rebase your patches(unless it fails and then you'd have to apply them manually).
You will need to use repo start command to create a topic branch that tracks the remote repo branch. Or you need to use --track option of the git branch command to manually create a local branch with a remote tracking branch. Use the --set-upstream option of the git branch command to add a tracking branch to an existing local branch.
Once you have setup the tracking branch correctly, the repo sync command will fast forward and reapply your local patches as Anton Cherkashyn has described in his answer.
Use gerrit in conjunction with repo and git.
This seems to work for me.
First mentioning some setup
# cd to root of source tree
repo start MyBranch # Create working branch for all projects
repo checkout MyBranch # switches all projects to use MyBranch
Time passes, fabulous edits made and committed (in MyBranch), working branch is clean. Now want upstream changes ...
# 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
The "repo sync -d" may not be necessary but hasn't caused any problems as far as I have seen. Plus it pulls the master codeline locally to keep it in sync for handy diffs and such.
Perhaps "repo sync" from within MyBranch does that too. But I don't seem to get any updates when I omit the "repo sync -d" step and just do "repo sync" when MyBranch is checked out. (Although maybe my local setup is messed up somehow)
To summarize:
Option A: Might work
cd RootOfRepoSourceTree # wherever you have it
repo checkout MyBranch
repo sync
Option B: Works consistently for me
cd RootOfRepoSourceTree # wherever you have it
repo sync -d -j12
repo checkout MyBranch
repo sync