I am new to Git and do not understand everything yet. I usually commit after each app update and then create a new branch for the next app version, so that I can correct bugs of the currently published version while working on improving the app for future versions.
So far it was just a precaution and I never really used it that way but I want to get serious about Git capabilities. And I face this problem:
I have two branches in addition to the master, and if I compare the files from the two branches, I can clearly see the differences.
However, if I "checkout" from one branch to the other, nothing happens and it seems that the current code is just reassigned to a different branch.
But what I want to do is to be able to modify both codes in parallel.
How does it work?
Thanks.
First you have to do the changes in one branch. Then you can share the same change to other branch using git. There are multiple ways to share the changes, based on the different scenario.
They are "Cherry pick", "patch", "merge" and "stash"(additionally shelve in android-studio).
Based on the scenario shared above, you can use patch to share the code among branches.
Make changes in one branch and commit it.
Right click the commit in android-studio and select "create patch".
Checkout to another branch.
Select options VCS ---> Apply Patch.
Select the "patch" file and apply it.
Now you can able to see the changes you made in the "other branch" in "current branch".
Then you can commit the changes in the regular way.
Related
I am not sure if it's possible to compare master branch (or any other) with the current feature branch like GIT does.
I want the Diff between two branches (master and feature branch) so that I can compare the diff before merging.I find Git UI less user friendly. As in AS I can traverse through code and change it right there.
I have found an option where I can compare any branch with my current local branch (that seem's like a solution to me but when I used it I got very confused).
Compare with current feature of AS compare two brach with specific selected commit.
While what I required is compare latest of both. (head of feature branch with head of master).Like we get in merge request of Git.
P.S- I thought of selecting all commit's to get the whole diff but it give a very different result something mix of all the diff's.
Want to get something like this.
I compare by right clicking my 'app' directory --> git --> compare with branch
This is how I check code before I merge it into master:
1.) Create and check out 'master' branch or one that has the same code as what's in master. (This can be done via the Terminal tab in Android Studio.)
git checkout master
OR
git checkout master_code_review_branch
2.) Run this command in the terminal to copy the commits from the branch you wish to compare (ex. ORIGIN/BRANCH_TO_MERGE) into the branch you've checked out. It will not commit.
git merge --no-commit --no-ff ORIGIN/BRANCH_TO_MERGE
3.) Now you can see all the individual changes in Android Studio by checking the "Version Control" tab or in the "commit" confirmation menu.
When done, you can "Abort Merge" in Android studio UI or via this terminal command:
git reset --merge --hard
More details here if you're interested:
https://medium.com/#mkutlev/pull-request-review-with-intellij-idea-or-android-studio-e60fbb3e3639
There doesn't appear a direct way. But there is a way if you look closely.
No need to make a new branch, if you can spot a branch which has
last commit on a previous time compared to the commit you want to
compare with.
If not, just make a local branch by title of your choice.
Use "Compare with Branch..."
All the commits between the selected branch head appear in the table. So spot your needed commit here.
Use the tabs titled Log or Files for comparing the revisions better.
We have a recent requirement at my workplace wherein we have a baseline Android project (trunk). Other projects will need to (svn) branch out from this baseline Android project and start their own line of development.
Now let's say that the current state of my svn is:
--r19--------r30----->my.package.baseline(trunk)
|
|--r24--r29------>my.newpackage.projectA(branch)
r19: created the projectA branch
r24: renamed my branch package
r29: made huge updates
r30: bug fixes and upgrades to baseline project
If I want to apply r30 to all my other branches, would it work fine if I do svn merge even if the directory/package has already changed due to r24?
If what you are asking is just would you able to commit, the answer is yes.
If you are lucky enough that files been changed in r24 and r29 are just different files with what's changed in r30, then it would just work without any problem.
If some files got changed in r24 or r29 has also been touched in r30 then you might run into a svn conflict, it will work still as long as the person perform the merge understand code changes in both branches(trunk and your branch), this person not just need to solving obvious svn conflict(same area in one file been changed in both branches), but also need to solve the code logic conflict, that I mean things like no svn conflict but it won't compile anymore, or the logic conflict between changes introducing new bugs in your code.
My suggestion here though, after the merge, commit immediately after solving svn conflict, don't worry about any logic conflict. You solve the logic conflict in a separate new commit. This will save your some rare trouble when you merge back into trunk from my experience. As what the svn does with the merge, it modify the mergeinfo attribute, for your example mergeinfo in your branch would be something like
trunk: r30
svn would be using this information to figure out how should it perform a merge when you decide to merge back into trunk, if your branch has everything from trunk to date, it simply replace trunk with your branch assuming your solved all conflict, if you do cherry-pick however, it use thing merge info differently to try to solve conflict automatically if possible, so if you commit logic fix in a different commit it would less likely run into svn conflict.
The longer a feature branch runs the more problem you would be facing if trunk keeps changing in the meantime. But it is what it is, that's how branching works, you should have a plan about how often you are going to merge from trunk and how long you want to keep your branch. Try to slice your task to smaller pieces so your branch has a shorter life span, for example two weeks, it would make a big difference comparing you keep a branch for three month and then merge back all those changes into trunk.
I am new to Android Studio and have began developing a Navigation Drawer app.
After having made a mistake in a commit, I played around with the Version control's "Checkout Revision" and now I can no longer push my project onto Github due to a "Detached HEAD".
How can I fix this problem? My app runs perfectly fine in the emulator.
Thanks
you can go to VCS menu then Git, Branches, then in Git Branches dialog click on item below local branches then checkout branches and then accept your default branches.
it will connect your project to it's default branch and you can commit your project.
If you already made a lot of changes and want to commit and push online but out of sudden got this detached head issue, here are steps you can do for Git through Android Studio:
Go to VCS -> Git -> Branches...
Click the +New Branch, just put any temporary name.
Then commit your changes to the new branch (don't push yet, since it'll create new branch online).
Go to VCS -> Git -> Branches... again and now select the previous branch(local) with the detached head issue and click checkout branch.
Go to VCS -> Git -> Branches... again and now select the newly created branch(local) and select merge into current.
After success merge, double check if your code is the latest one. Now you can push the branch(previously got issue) without detached head issue. If you click commit at this point there'll be nothing to be committed since you have merged the latest changes. All you need to do is just push online. By this you prevent yourself from creating new branch online just to fix this issue.
For cleaning purpose, once you managed to push the branch online, just select again the newly created branch(local) and click delete branch.
When you are in a 'detached head state' in Git, it means you are currently viewing history according to a past commit that is not on a branch. A few things need to happen based on what your goal is.
If you want to continue your code in the currently checked out version? If so, you should check back out to the most recently made commit and then un-do history with git revert or git reset, whichever makes more sense for you.
If you want to just go back to your most recent commit and continue to work as normal, git checkout <newest SHA> will work totally fine.
To get rid from Detached Head you need to know why this problem is arrived. Its Showing Detached Head because you merge your project several times(or atlas twice) by just committing your project locally. What you need to do is that by every time you merge your project just commit it locally as well as to server branch too.
This will resolve your problem as it does mine.
The easiest quick solution is just to create new branch and push your current version there.
However, this solution is not the right one.
I created a branch and copy a commit to this one with command
git cherry-pick <commit number>
I have two branches, the development and the master.
Code in master branch can't have Log calls, comments, etc . Everything else is the same.
So when I merged to the master before commit I deleted everything I didn't want.
I continued developing on development branch and now I want to merge and commit the changes but I guess that will add again what I have previous deleted.
Is there a way to commit only the changes from the development branch or a workflow/solution for this problem ?
I'm using mercurial but I guess someone who is facing the same problem with git can help.
I'm new with mercurial and don't know much about git.
Thank you
Ideally you need to find a different method for tracking/sharing such items but if that is impossible then you could possibly use python hooks to filter them out of any commits to your master branch.
See this chapter of the hgbook for some discussion of some of the possibilities.
So I have managed to get a couple apps up on the marketplace only to have a stray thought of what is the best way to go about managing my projects/apps within eclipse to accommodate future updates to the marketplace. My question resides within Eclipse and what to do with my projects/apps as I apply updates.
Do I simply copy my project/app, paste it and the increment the version information accordingly? Or am I continuously working on my published project/app? Or...Is there a recommended/preferred method of going about this. Since they are up and good on the marketplace I am leery of doing something that will cause problems for me later on down the line.
And don't change the package name....correct?
This is what I currently have on the Marketplace...
Wind Chill Calculator
True Love Game
First of all, everyone's posts were very helpful and I have spent some time looking over documentation through the links provided.
So...and brace for impact as I say this. Being one who has NEVER used any form of SCM for my projects this is all new to me (as everyone's faces cringe), which is why I am asking the original question in the first place. I hate to say tell me anything without doing my research...so within the past few hours using git within eclipse I have gleamed the following:
Team > Share Project ...ignores...any tags(for version info)which is what I am after...commits...THEN
Clone? File -> Import -> Git -> Git Repository at this point once I have cloned my project do I create a new tag with the new version info, and go through the commit process again? If this is the case I now have two items in my Git Repository. One of which has the single tag of 1.0, and the other item which contains two tags 1.0 and 1.1, and when I look at the history I see two tags Version 1.0 and Version 1.1. Then I just switch between the resources I need from within the repository?
I just want to make sure my process is correct before I begin to implement some of this on existing projects that are pretty extensive already. As for the rest I am just going to learn on the fly...branches
You might want to use a revision control system like SVN or git or one of dozens of other options, and continuously update the single project in Eclipse. The benefit of using source control is that you can branch into a new project for major changes, update your existing code for minor changes, and tag the branches so you can revert back to an old snapshot in the future.
I personally use bitbucket which is hosted remotely and is free. It supports SVN and Mercurial.
No, dont change the package name, that will make it new app, instead of upgrade of original.
Use a version control system, like SVN.
Manage Tags for a complete working state of code(through svn), so you can always revert back to that tag.
When ready for new release, increment version no. etc and update on market...
EDIT After addition in question:
Don't get much confused with various GIT/SVN working.. There main purpose is that they will allow you to switch your code back and forth to any point in past, that allows you to code in a way properly knowing that you can always revert back to a Working state.. and it is definitely of much more benefit in a Team , when multiple people are working on same codebase and possibly same files...
Being a long-time user of SVN, I recommend subclipse (svn for eclipse). When you're ready to release another version of your app, create a 'tag' for the release version and you'll always be able to go back to that exact version.
SVN has excellent docs. There is also TortoiseSVN for repo work outside of eclipse.