Merge branches in git on Android Studio - android

I have a problem with merging branches in Android Studio.
If I want to merge my local master with my remote master, the Android Studio alerts me that there were changes between the remote and the local, and asks me to commit and push the changes. but when I try to push the changes it says that I need to save or stash the changes.
Is there an easy way to work with the git in Android Studio?

It sounds like you have unstaged changes. I don't know about how to do this from android studio, git status should show you what state things are in. If you have unstaged changes, first you need to 'stage' or add your changes (git add .) then create a commit from the changes you added (git commit).
Next, it sounds like there are changes in the remote master that you want to incorporate into your local state. Before you do, if it's been a while since you fetched/pulled, you might want to get the latest master from the server using git fetch. Then you either need to combine your changes with the changes from the remote master (git merge origin/master), or re-apply your changes on top of the remote master (git rebase origin/master).
Alternatively, if you haven't made any commits yet, and all your work is in the form of unstaged changes, you can stash them (git stash) to temporarily store them away, then use git pull to update to the latest version of master, followed by git stash pop to apply the changes you previous stored.

Related

How to push my local commit when my github have another commit and i forgot to pull my commit in github

Hi i'm here to asking you, how to push my commit/chage(s) when i have another commit and i forgot to pull the commit from github.
This is the chronology: when i'm no have another work, i decide to make own project and i use git to be my vcs, and then i make my project to be repository.
A few day's later, i decide to remoting my github.
Everything is alright until the problem come. In one day, i'm edit my README.md and save the change, in git same to but a different is i updating my source code and save the change. After that i'm push my commit and this is happent.
Screen shoted the problem
But in here, i'm not realize i'm forgot to pull a commit from github until i'm realized that.
So please help me! I stuck in this condition! Please!
And i'm sorry if my English is bad
So, basically your solution might be to pull the changes from GitHub (that is, if I understand correctly you have did some changes to you remote Github - updated your README.md - not from your local - now you want that change to be reflected in your local and you need to push your new changes in the local to the remote).
The best solution would be to first add all your changes to staging and then committing by doing:
git add .
git commit -m "Your commit message (One-liner of your change)"
and then do a rebase as follows:
git pull --rebase
Rebasing will pull the changes from the remote, and re-apply your local changes on top of it, thus your local repo is now in sync with the remote repo (they are essentially in the same state). Now you can do the push:
git push <REMOTENAME> <BRANCHNAME>

How to revert back to old code after pull

hope you are having a good day.
I want to know a small thing about pull/push in git repo.
Below is the representation of my code/project.
Blue: This is my code which is worked on and without commit i pulled the red code from git.
Red: This is the older version of blue code.
Yellow: this is the code which i have now
So i have worked on blue code but without commit or push i pulled red code, so it over writes my blue updated code and merged as yellow code. So now i want to get back my blue code, is it possible? i searched in my project folder but i cant find it. i search on my git branch code too but it wasn't there too.
Thanks for the read, if you know how to revert that pull request it will save my couple of hours. Thanks again
And by the way this is an android project and code is in bitbucket.
[UPDATE] - Solved-
Thanks for the response. I got my blue code back using Android Studio Local History tool. Reverted all the changes that i have made.
Try git lola9 (if you've set up the alias, or whatever way you prefer to view your commit history), and you should see the commits you pulled. Alternatively, the console output of the git pull should also include the commits you pulled.
Once you have that, what I would do is:
Note the number of commits you want to git rid of
git stash your changes,
git reset head~n, where n is the number of commits we figured out earlier. This will 'un-commit' the changes you pulled
git co . & git reset as needed to 'lose' all those now un-commit-ed changes that you've pulled down
git stash apply to retrieve your changes (rather than pop in case somethings gone wrong, you don't want to dirty your changes)

How to reset to my last commit in Android Studio

I commit changes to git from Android Studio, after that I have made some changes in my project that gives me errors, and now I want to get back that commited version that has no errors.
How can I do that?
To undo your latest changes and reset to the most recent commit:
Go to VCS -> Git -> Reset HEAD..
Change Reset type to hard to remove those changes.
It will look like this. You can validate the reset before you do it if you want.
What happens if you click Validate?
A screen will pop up that shows the changes that were made in the commit you are about to reset to. You can view diffs per file that show what the commit changed in that file. It's more or less equal to what $ git show in a terminal would do.
Contrary to what I assumed before, it does not show what files will be affected when you perform the reset.
Just get your commit id using git log. Then you can use (with 0d1d7fc32 for example):
# This will detach your HEAD, that is, leave you with no branch checked out:
git checkout 0d1d7fc32
or if you don't want to save your changes (hard reset):
# This will destroy any local modifications.
# Don't do it if you have uncommitted work you want to keep.
git reset --hard 0d1d7fc32
If you want to go back to the last commit (without saving changes), then no need to get the id, go for:
git reset --hard HEAD
From this post
git reset --soft "HEAD^"
this will remove the latest commit.
According to this great article on jetbrains webiste here:
Reset a branch to a specific commit
If you notice an error in a set of recent commits and want to redo that part, you can roll back your repository to a specific state. This is done by resetting the current branch HEAD to a specified commit (and optionally resetting the index and working tree if you prefer not to reflect the undo in the history).
Open the Version Control tool window Alt+9 and switch to the Log tab.
Select the commit that you want to move HEAD onto and select Reset
Current Branch to Here from the context menu.
In the Git Reset dialog that opens, select how you want your working
tree and the index to be updated and click Reset:
Soft: all changes
from commits that were made after the selected commit will be staged
(that means they will be moved to the Local Changes view so that you
can review them and commit later if necessary).
Mixed: changes made after the selected commit will be preserved but will not be staged for commit.
Hard: all changes made after the selected commit will be discarded (both staged and committed).
Keep: committed changes made after the selected commit will be discarded, but local changes will be kept intact.
Suppose you want to commit project changes. When you want to commit files Android Studio will show you which files have been changed. See them and you can convert every file you want to last commit.

When using repo tool how to delete all commits but keep my changed files?

Im using the repo tool to sync android source.
I have two questions about this;
When I change something in the source and sync later on but want to keep the changes, what is the correct way to do this? (im now doing git add ., git commit and later on merge if necessary) But this seems not to be the right way.
Can I reset the entire repo (all git dirs) to remove all commits but still keep all my changed files? (because they are all polluted with commits now)
Thanks.
As Far As I know repo does this for you. Once its done with sync it rebase you chanegs on TOP of that.
Or else you can try
git pull --rebase

How to most efficiently tie a git build version number, to an apk version with eclipse?

I use eclipse to build an android app, and git running locally for version control. Currently I have a value in strings.xml that represents the version number. If i change that number, the very next thing I do is a code commit in git using the same version number in the comment, so that I can tie a specific build to the matching code that generates it. Very manual process.
Larsks comment helped in pointing me in a direction of defining things better. I think what I want is some type of git hook. Something where, if I change a particular version variable, it will automatically add a corresponding tag. Or, if I issue a tag of a specific format "v3.1.4", it will update the version number in code.
I think prior to reading about hooks, I was hoping for something where I could put "ReplaceWithVersion", or some other special code, and on commit git would know automatically to replace that with the current tag/version.
Am I hoping for too much? Is there a feasible way to get that the versions/tags in sync?
This sounds like the precut use for git tags. After you update strings.xml and commit the change, tag the commit with the version number:
git tag 3.14.15
You can then use this tag in other git commands to refer to this specific commit. For example, too see any change you've made since a release:
git diff 3.14.15

Categories

Resources