I checked out new branch from develop, and made a commit for a single file.When pushing, it also includes the top 3 commits from the tree shown. I only wanted the single commit I made in the new branch to be pushed
If this commit is not related to commits you don't want to push, you can do that and need to start with proper rebase.
In terminal it would be command:
git rebase -i HEAD~3
This will open editor with such content:
pick 11af733 Oldest commit
pick 085693f Some commit
pick d9242c1 Commit you want to push
Now you need change order to have commit you want to push on top. Then you can checkout it and push to specific branch
git checkout <sha of commit, in my case d9242c1>
git push origin HEAD:develop
You can do it from Android studio as well under Git / Interactively Rebase from Here to see similar screen.
Related
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 want to discard the local changes I made in an Android Studio project.
I tried to perform a pull, the GUI gives me 5 options, which option should I choose?
Octopus
Ours
Subtree
Recursive
Resolve
In Android Studio do the following:
-Open the Version Control tool window Alt+9 and switch to the Log tab.
-Select the recent commit and right click on it than select Reset Current Branch to Here.
-A Git Reset popup will open -> select Hard -> click Reset
You originally asked which strategy argument to use with git pull to discard your own work (there is a pending edit that will change the question, if the edit is approved). The answer is: None.
Don't use git pull at all. Run git fetch first:
git fetch origin
This brings over all the new stuff from the other Git you have your Git calling "origin".
Now that you have everything they have, simply stop using what you have been using, and switch to theirs:
git reset --hard origin/master # assuming you're on your "master"
You may also want to use git clean -fdx to remove build artifacts, but that's a separate issue.
In Android studio do the following:
Go to VCS -> Git -> Reset HEAD
Change Reset type to hard
I made some commits to git from android studio. Now I want to reset to one of the committed version. How can I do that within android studio?
At last I have found the solution.
Go to VCS -> Git -> Show History
From Log, right click on the required committed version and select Reset Current Branch to Here.
Select Hard and click on Reset button.
open terminal in android studio :
You can do this by following two commands:
git reset --hard [previous Commit SHA id here]
git push origin [branch Name] -f
It will remove your previous git commit.
If you want to keep your changes you can also use:
git reset --soft [previous Commit SHA id here]
Then it will save your changes.
For more details How do you undo the last commit?
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