Git fails to pull error unrelated histories - android

So I have an android studio project that I'm syncing between my laptop and my computer with git. Every time I push with one and pull with the other when I try to pull I get error refusing to merge unrelated histories
I tried using --allow-unrelated-histories but that causes a ton of merge conflicts.
I need to be able to sync between the two because my computer supports the emulator and my laptop is portable.

This happens because your repositories was initialized independly.
You should create the repository only in one location, and clone it to the other.
If the other repository already exists and you have there some change which you don't want to lose, you could do the following:
(from location2, commit all uncommitted changes first!)
git fetch location1
git branch save_location2
git reset --hard origin/location1
So you switch to the history started at location1, and would not lose your history started at location2, and will be able to look up stuff from there.
There are exceptional cases where you should use --allow-unrelated-histories, but I'm sure it is not your case.

I had same problem. Try this:
git pull origin master --allow-unrelated-histories
git push origin master
Reference:- Github unrelated histories issue

Related

How to configure Android studio with gerrit commit and push

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.

Android Studio changing code automatically

Something very weird is happening.
I am on the master branch of my repository. After calling git pull I get the latest version of the code on the master branch, everything is ok.
But for some reason, Android Studio, after some seconds, changes the code, so that now, even if I do git pull I get Already up-to-date but if I call git status I see changes not staged in red. How is that possible?
Also, if I click cmd+z I can see for few seconds how the code added by Android Studio goes away, and immediately comes back.
I tried deleting the entire project and cloning again from the repository, and again I get the latest version of the fresh code, but after few seconds Android Studio changes it.
All that happens in a particular file and section of code.
When you make git pull it doesn't reset or throw the changes you have non staged, you have to commit them the only reason you would see a problem with these files were is there was a conflict and git would notify you and tell you you need to commit before the pull.
so if you want to commit these change you need to do:
git add .
git commit
or if you want to throw away these changes you need to do:
git reset --hard HEAD
that last command would let you with the exact same code as in the remote repository.
That's happening because each time you opening a project with Android Studio, it will check for Android Studio project configuration files. When Android Studio did not find any of these files, it will create them. The configuration files will be in the .idea folder. Therefore, you will see a red mark for those unstaged files.

Git status head detached after git reset --hard

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

What does smart merge do in Android Studio?

In Android studio there are options at the bottom right corner to handle branches. In Merge option when I merge another remote or local branch, it shows me options like Force merge and smart merge.
What exactly they do?
When merging with local/remote branches?
its similar to Smart Checkout. Android Studio will stash local changes, check out the selected branch, and then unstash the changes. If a conflict occurs during the unstash operation, you will be prompted to merge the changes.
Smart merge executes the following commands:
git stash save "Uncommitted changes before Update at <MM/DD/YY>, <HH:MM>"
git merge <remote>
git stash pop (if merge successful)
If the merge is unsuccessful and you abort or discard changes, you'll need to run git stash pop yourself to get back your changes.
You can see the exact commands being executed by examining the Version Control context in Android Studio, in the Console tab:

Contribute on GitHub using Android Studio

I'm not new to using GitHub on Android Studio, but:
This is my first try to contribute to a sample project for Android on GitHub.
I did the following
I cloned the repository:
I made my changes
I committed my changes
I pushed my commit
And baam (here is the problem):
Why? What things did I miss?
(Don't forget, I have never contributed on GitHub, and this is my first time.)
403 indicates that you are not allowed to access the resource - you aren't authenticated with GitHub. To fix this, you should change your remote URL to a repository you have access to, then push your changes:
https://myusername#github.com/user/repo.git
From the command line you would need to do the following (Android Studio should automatically detect the changes):
git remote remove origin
git remote add origin https://myusername#github.com/user/repo.git
git push -u origin --all // prompts for authentication, pushes your changes to github
Your question has nothing to do with Android Studio, I guess if you try to push your changes through command line you'll get the same result. Read about Contributing to Open Source on GitHub.
First of all, to do a contribution:
You must fork the repository
Clone your fork version of that repository
Through the command line, navigate to your clone directory then add upstream version (original repository):
$ git remote add upstream https://github.com/fcannizzaro/material-stepper.git
You can check it using the line $ git remote, and you will see origin and upstream.
Make changes → commit them → then push (all of this happen on your repository (forked one), not the upstream).
Go and check the network graph for both the forked and original repositories.
Go to the GitHub original repository's link and click pull request.
Do as described in this image:
And fill the others field and click Create pull request
Thanks for Erik Carlsten's tutorials.

Categories

Resources