How to make project snapshots in android-studio - android

I am new to Android Studio and to Android Development as well. I am presently using version 1.3.1.
My question is how to efficiently make project "snapshots". - I am not absolutely sure the term of "snapshot" is good hence the quotes.
What I mean is to save the project as is at the moment and be able to make heavy changes without fearing to destroy what is already working well and also to be able to restart from this "snapshot" if it happens that the changes made break the project.
In other terms, how can I manage versions?

This can be achieved using a version control program such as git or svn, although git tends to be the industry standard tool.
You can follow a very simple online tutorial to get started quickly with the basics behind git. There are also a number of other excellent resources such as the git guide by Tower and the git book.
In regards to versioning, you can use git tag to tag specific versions (see docs)
#Create a new tag
git tag -a v1.0 -m 'Version 1.0'
#Create a new working branch 'version_2_dev' from v1.0
git checkout -b version_2_dev v1.0

You need to add the version control plug-ins like bitbucket, svn and git.

Related

Making backup with Git in android studio [duplicate]

Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
Ok, after seeing this post by PJ Hyett, I have decided to skip to the end and go with Git.
So what I need is a beginner's practical guide to Git. "Beginner" being defined as someone who knows how to handle their compiler, understands to some level what a Makefile is, and has touched source control without understanding it very well.
"Practical" being defined as this person doesn't want to get into great detail regarding what Git is doing in the background, and doesn't even care (or know) that it's distributed. Your answers might hint at the possibilities, but try to aim for the beginner that wants to keep a 'main' repository on a 'server' which is backed up and secure, and treat their local repository as merely a 'client' resource.
So:
Installation/Setup
How to install Git
How do you set up Git? Try to cover Linux, Windows, Mac, think 'client/server' mindset.
Setup GIT Server with Msysgit on Windows
How do you create a new project/repository?
How do you configure it to ignore files (.obj, .user, etc) that are not really part of the codebase?
Working with the code
How do you get the latest code?
How do you check out code?
How do you commit changes?
How do you see what's uncommitted, or the status of your current codebase?
How do you destroy unwanted commits?
How do you compare two revisions of a file, or your current file and a previous revision?
How do you see the history of revisions to a file?
How do you handle binary files (visio docs, for instance, or compiler environments)?
How do you merge files changed at the "same time"?
How do you undo (revert or reset) a commit?
Tagging, branching, releases, baselines
How do you 'mark' 'tag' or 'release' a particular set of revisions for a particular set of files so you can always pull that one later?
How do you pull a particular 'release'?
How do you branch?
How do you merge branches?
How do you resolve conflicts and complete the merge?
How do you merge parts of one branch into another branch?
What is rebasing?
How do I track remote branches?
How can I create a branch on a remote repository?
How do I delete a branch on a remote repository?
Git workflow examples
Other
Describe and link to a good GUI, IDE plugin, etc. that makes Git a non-command line resource, but please list its limitations as well as its good.
msysgit - Cross platform, included with Git
gitk - Cross platform history viewer, included with Git
gitnub - Mac OS X
gitx - Mac OS X history viewer
smartgit - Cross platform, commercial, beta
tig - console GUI for Linux
qgit - GUI for Windows, Linux
Git Extensions - package for Windows, includes friendly GUI
Any other common tasks a beginner should know?
Git Status tells you what you just did, what branch you have, and other useful information
How do I work effectively with a subversion repository set as my source control source?
Other Git beginner's references
Git guide
Git book
Git magic
gitcasts
GitHub guides
Git tutorial
Progit - book by Scott Chacon
Git - SVN Crash Course
Git from the bottom up
Git ready
gitref.org
Git visual cheatsheet
Delving into Git
Understanding Git conceptually
Git for computer scientists (and another version)
I will go through the entries from time to time and 'tidy' them up so they have a consistent look/feel and it's easy to scan the list - feel free to follow a simple "header - brief explanation - list of instructions - gotchas and extra info" template. I'll also link to the entries from the bullet list above so it's easy to find them later.
How do you create a new project/repository?
A git repository is simply a directory containing a special .git directory.
This is different from "centralised" version-control systems (like subversion), where a "repository" is hosted on a remote server, which you checkout into a "working copy" directory. With git, your working copy is the repository.
Simply run git init in the directory which contains the files you wish to track.
For example,
cd ~/code/project001/
git init
This creates a .git (hidden) folder in the current directory.
To make a new project, run git init with an additional argument (the name of the directory to be created):
git init project002
(This is equivalent to: mkdir project002 && cd project002 && git init)
To check if the current current path is within a git repository, simply run git status - if it's not a repository, it will report "fatal: Not a git repository"
You could also list the .git directory, and check it contains files/directories similar to the following:
$ ls .git
HEAD config hooks/ objects/
branches/ description info/ refs/
If for whatever reason you wish to "de-git" a repository (you wish to stop using git to track that project). Simply remove the .git directory at the base level of the repository.
cd ~/code/project001/
rm -rf .git/
Caution: This will destroy all revision history, all your tags, everything git has done. It will not touch the "current" files (the files you can currently see), but previous changes, deleted files and so on will be unrecoverable!
GUIs for git
Git GUI
Included with git — Run git gui from the command line, and the Windows msysgit installer adds it to the Start menu.
Git GUI can do a majority of what you'd need to do with git. Including stage changes, configure git and repositories, push changes, create/checkout/delete branches, merge, and many other things.
One of my favourite features is the "stage line" and "stage hunk" shortcuts in the right-click menu, which lets you commit specific parts of a file. You can achieve the same via git add -i, but I find it easier to use.
It isn't the prettiest application, but it works on almost all platforms (being based upon Tcl/Tk)
Screenshots | a screencast
GitK
Also included with git. It is a git history viewer, and lets you visualise a repository's history (including branches, when they are created, and merged). You can view and search commits.
Goes together nicely with git-gui.
Gitnub
Mac OS X application. Mainly an equivalent of git log, but has some integration with github (like the "Network view").
Looks pretty, and fits with Mac OS X. You can search repositories. The biggest critisism of Gitnub is that it shows history in a linear fashion (a single branch at a time) - it doesn't visualise branching and merging, which can be important with git, although this is a planned improvement.
Download links, change log and screenshots | git repository
GitX
Intends to be a "gitk clone for OS X".
It can visualise non-linear branching history, perform commits, view and search commits, and it has some other nice features like being able to "Quicklook" any file in any revision (press space in the file-list view), export any file (via drag and drop).
It is far better integrated into OS X than git-gui/gitk, and is fast and stable even with exceptionally large repositories.
The original git repository pieter has not updated recently (over a year at time of writing). A more actively maintained branch is available at brotherbard/gitx - it adds "sidebar, fetch, pull, push, add remote, merge, cherry-pick, rebase, clone, clone to"
Download | Screenshots | git repository | brotherbard fork | laullon fork
SmartGit
From the homepage:
SmartGit is a front-end for the
distributed version control system Git
and runs on Windows, Mac OS X and
Linux. SmartGit is intended for
developers who prefer a graphical user
interface over a command line client,
to be even more productive with Git —
the most powerful DVCS today.
You can download it from their website.
Download
TortoiseGit
TortoiseSVN Git version for Windows users.
It is porting TortoiseSVN to TortoiseGit The latest release 1.2.1.0 This release can complete regular task, such commit, show log, diff two version, create branch and tag, Create patch and so on. See ReleaseNotes for detail. Welcome to contribute this project.
Download
QGit
QGit is a git GUI viewer built on
Qt/C++.
With qgit you will be able to browse
revisions history, view patch content
and changed files, graphically
following different development
branches.
Download
gitg
gitg is a git repository viewer
targeting gtk+/GNOME. One of its main
objectives is to provide a more
unified user experience for git
frontends across multiple desktops. It
does this not be writing a
cross-platform application, but by
close collaboration with similar
clients for other operating systems
(like GitX for OS X).
Features
Browse revision history.
Handle large repositories (loads linux repository, 17000+ revisions, under 1 second).
Commit changes.
Stage/unstage individual hunks.
Revert changes.
Show colorized diff of changes in revisions.
Browse tree for a given revision.
Export parts of the tree of a given revision.
Supply any refspec which a command such as 'git log' can understand to built the history.
Show and switch between branches in the history view.
Download: releases or source
Gitbox
Gitbox is a Mac OS X graphical
interface for Git version control
system. In a single window you see
branches, history and working
directory status.
Everyday operations are easy: stage
and unstage changes with a checkbox.
Commit, pull, merge and push with a
single click. Double-click a change to
show a diff with FileMerge.app.
Download
Gity
The Gity website doesn't have much information, but from the screenshots on there it appears to be a feature rich open source OS X git gui.
Download or source
Meld
Meld is a visual diff and merge tool.
You can compare two or three files and
edit them in place (diffs update
dynamically). You can compare two or
three folders and launch file
comparisons. You can browse and view a
working copy from popular version
control systems such such as CVS,
Subversion, Bazaar-ng and Mercurial
[and Git].
Downloads
Katana
A Git GUIfor OSX by Steve Dekorte.
At a glance, see which remote branches
have changes to pull and local repos
have changes to push. The git ops of
add, commit, push, pull, tag and reset
are supported as well as visual diffs
and visual browsing of project hieracy
that highlights local changes and additions.
Free for 1 repository, $25 for more.
Download
Sprout (formerly GitMac)
Focuses on making Git easy to use. Features a native Cocoa (mac-like) UI, fast repository browsing, cloning, push/pull, branching/merging, visual diff, remote branches, easy access to the Terminal, and more.
By making the most commonly used Git actions intuitive and easy to perform, Sprout (formerly GitMac) makes Git user-friendly. Compatible with most Git workflows, Sprout is great for designers and developers, team collaboration and advanced and novice users alike.
Download | Website
Tower
A feature-rich Git GUI for Mac OSX. 30-day free trial, $59USD for a single-user license.
Download | Website
EGit
EGit is an Eclipse Team provider for the Git version control system.
Git is a distributed SCM, which means every developer has a full copy
of all history of every revision of the code, making queries against
the history very fast and versatile.
The EGit project is implementing Eclipse tooling on top of the JGit
Java implementation of Git.
Download | Website
Git Extensions
Open Source for Windows - installs everything you need to work with Git in a single package, easy to use.
Git Extensions is a toolkit to make working with Git on Windows more intuitive. The shell extension will intergrate in Windows Explorer and presents a context menu on files and directories. There is also a Visual Studio plugin to use git from Visual Studio.
Download
Big thanks to dbr for elaborating on the git gui stuff.
SourceTree
SourceTree is a free Mac client for Git, Mercurial and SVN. Built by Atlassian, the folks behind BitBucket, it seems to work equally well with any VC system, which allows you to master a single tool for use with all of your projects, however they're version-controlled. Feature-packed, and FREE.
Expert-Ready & Feature-packed for both novice and advanced users:
Review outgoing and incoming changesets.
Cherry-pick between branches.
Patch handling, rebase, stash / shelve and much more.
Download | Website
Well, despite the fact that you asked that we not "simply" link to other resources, it's pretty foolish when there already exists a community grown (and growing) resource that's really quite good: the Git Community Book. Seriously, this 20+ questions in a question is going to be anything but concise and consistent. The Git Community Book is available as both HTML and PDF and answers many of your questions with clear, well formatted and peer reviewed answers and in a format that allows you to jump straight to your problem at hand.
Alas, if my post really upsets you then I'll delete it. Just say so.
How to configure it to ignore files:
The ability to have git ignore files you don't wish it to track is very useful.
To ignore a file or set of files you supply a pattern. The pattern syntax for git is fairly simple, but powerful. It is applicable to all three of the different files I will mention bellow.
A blank line ignores no files, it is generally used as a separator.
Lines staring with # serve as comments.
The ! prefix is optional and will negate the pattern. Any negated pattern that matches will override lower precedence patterns.
Supports advanced expressions and wild cards
Ex: The pattern: *.[oa] will ignore all files in the repository ending in .o or .a (object and archive files)
If a pattern has a directory ending with a slash git will only match this directory and paths underneath it. This excludes regular files and symbolic links from the match.
A leading slash will match all files in that path name.
Ex: The pattern /*.c will match the file foo.c but not bar/awesome.c
Great Example from the gitignore(5) man page:
$ git status
[...]
# Untracked files:
[...]
# Documentation/foo.html
# Documentation/gitignore.html
# file.o
# lib.a
# src/internal.o
[...]
$ cat .git/info/exclude
# ignore objects and archives, anywhere in the tree.
*.[oa]
$ cat Documentation/.gitignore
# ignore generated html files,
*.html
# except foo.html which is maintained by hand
!foo.html
$ git status
[...]
# Untracked files:
[...]
# Documentation/foo.html
[...]
Generally there are three different ways to ignore untracked files.
1) Ignore for all users of the repository:
Add a file named .gitignore to the root of your working copy.
Edit .gitignore to match your preferences for which files should/shouldn't be ignored.
git add .gitignore
and commit when you're done.
2) Ignore for only your copy of the repository:
Add/Edit the file $GIT_DIR/info/exclude in your working copy, with your preferred patterns.
Ex: My working copy is ~/src/project1 so I would edit ~/src/project1/.git/info/exclude
You're done!
3) Ignore in all situations, on your system:
Global ignore patterns for your system can go in a file named what ever you wish.
Mine personally is called ~/.gitglobalignore
I can then let git know of this file by editing my ~/.gitconfig file with the following line:
core.excludesfile = ~/.gitglobalignore
You're done!
I find the gitignore man page to be the best resource for more information.
How do you 'tag' a particular set of revisions
How do you 'mark' 'tag' or 'release' a particular set of revisions for a particular set of files so you can always pull that one later?
Using the git tag command.
To simply "tag" the current revision, you would just run..
git tag -a thetagname
git tag -a 0.1
git tag -a 2.6.1-rc1 -m 'Released on 01/02/03'
To list the current tags, simply run git tag with no arguments, or -l (lower case L):
$ git tag -a thetagname # and enter a message, or use -m 'My tag annotation'
$ git tag -l
thetagname
To delete a tag, you use the -d flag:
$ git tag -d thetagname
Deleted tag 'thetagname'
$ git tag
[no output]
To tag a specific (previous) commit, you simply do..
git tag [tag name] [revision SHA1 hash]
For example:
git tag 1.1.1 81b15a68c6c3e71f72e766931df4e6499990385b
Note: by default, git creates a "lightweight" tag (basically a reference to a specific revision). The "right" way is to use the -a flag. This will launch your editor asking for a tag message (identical to asking for a commit message, you can also use the -m flag to supply the tag message on the command line). Using an annotated tag creates an object with its own ID, date, tagger (author), and optionally a GPG signature (using the -s tag).
For further information on this, see this post
git tag mytagwithmsg -a -m 'This is a tag, with message'
And to list the tags with annotations, use the -n1 flag to show 1 line of each tag message (-n245 to show the first 245 lines of each annotation, and so on):
$ git tag -l -n1
mytagwithmsg This is a tag, with message
For more information, see the git-tag(1) Manual Page
Workflow example with GIT.
Git is extremely flexible and adapts good to any workflow, but not enforcing a particular workflow might have the negative effect of making it hard to understand what you can do with git beyond the linear "backup" workflow, and how useful branching can be for example.
This blog post explains nicely a very simple but effective workflow that is really easy to setup using git.
quoting from the blog post:
We consider origin/master to be the main branch where the source code of HEAD always reflects a production-ready state:
The workflow has become popular enough to have made a project that implements this workflow: git-flow
Nice illustration of a simple workflow, where you make all your changes in develop, and only push to master when the code is in a production state:
Now let's say you want to work on a new feature, or on refactoring a module. You could create a new branch, what we could call a "feature" branch, something that will take some time and might break some code. Once your feature is "stable enough" and want to move it "closer" to production, you merge your feature branch into develop. When all the bugs are sorted out after the merge and your code passes all tests rock solid, you push your changes into master.
During all this process, you find a terrible security bug, that has to be fixed right away. You could have a branch called hotfixes, that make changes that are pushed quicker back into production than the normal "develop" branch.
Here you have an illustration of how this feature/hotfix/develop/production workflow might look like (well explained in the blog post, and I repeat, the blog post explains the whole process in a lot more detail and a lot better than I do.
Here's a copy of PJ Hyett's post, as it is not available anymore:
Git Isn't Hard
Nov 23, 2008
When we tell people why they should
use Git over Subversion, the go-to
line is, “Git does Subversion better
than Subversion, but it does a lot
more than that.”
The “lot more” is comprised of a bunch
of stuff that makes Git really shine,
but it can be pretty overwhelming for
those coming from other SCM’s like
Subversion.
That said, there’s nothing stopping
you from using Git just like you use
Subversion while you’re making the
transition.
Assuming you’ve installed the
necessary software and have a remote
repository somewhere, this is how you
would grab the code and push your
changes back with Subversion:
$ svn checkout svn://foo.googlecode.com/svn/trunk foo
# make your changes
$ svn commit -m "my first commit"
And how would you do it in Git:
$ git clone git#github.com:pjhyett/foo.git
# make your changes
$ git commit -a -m "my first commit"
$ git push
One more command to make it happen in
Git. That extra command has large
implications, but for the purposes of
this post, that’s all we’re talking
about, one extra command.
See, it really isn’t that hard.
Update: I’d be remiss to not also mention that the equivalent of
updating your local copy in Subversion
compared to Git is svn update and
git pull, respectively. Only one
command in both cases.
How to install Git
On Windows:
Install msysgit
There are several downloads:
Git: Use this unless you specifically need one of the other options below.
PortableGit: Use this if you want to run Git on a PC without installing on that PC (e.g. running Git from a USB drive)
msysGit: Use this if you want to develop Git itself. If you just want to use Git for your source code, but don't want to edit Git's source code, you don't need this.
This also installs a Cygwin bash shell, so you can use the git in a nicer shell (than cmd.exe), and also includes git-gui (accessible via git gui command, or the Start > All Programs > Git menu)
Mac OS X
Use the git-osx-installer, or you can also install from source
Via a package manager
Install git using your native package manager. For example, on Debian (or Ubuntu):
apt-get install git-core
Or on Mac OS X, via MacPorts:
sudo port install git-core+bash_completion+doc
…or fink:
fink install git
…or Homebrew:
brew install git
On Red Hat based distributions, such as Fedora:
yum install git
In Cygwin the Git package can be found under the "devel" section
From source (Mac OS X/Linux/BSD/etc.)
In Mac OS X, if you have the Developer Tools installed, you can compile Git from source very easily. Download the latest version of Git as a .tar.bz or .tar.gz from http://git-scm.com/, and extract it (double click in Finder)
On Linux/BSD/etc. it should be much the same. For example, in Debian (and Ubuntu), you need to install the build-essential package via apt.
Then in a Terminal, cd to where you extracted the files (Running cd ~/Downloads/git*/ should work), and then run..
./configure && make && sudo make install
This will install Git into the default place (/usr/local - so git will be in /usr/local/bin/git)
It will prompt you to enter your password (for sudo), this is so it can write to the /usr/local/ directory, which can only be accessed by the "root" user so sudo is required!
If you with to install it somewhere separate (so Git's files aren't mixed in with other tools), use --prefix with the configure command:
./configure --prefix=/usr/local/gitpath
make
sudo make install
This will install the git binary into /usr/local/bin/gitpath/bin/git - so you don't have to type that every time you, you should add into your $PATH by adding the following line into your ~/.profile:
export PATH="${PATH}:/usr/local/bin/gitpath/bin/"
If you do not have sudo access, you can use --prefix=/Users/myusername/bin and install into your home directory. Remember to add ~/bin/ to $PATH
The script x-git-update-to-latest-version automates a lot of this:
This script updates my local clone of the git repo (localy at ~/work/track/git), and then configures, installs (at /usr/local/git-git describe) and updates the /usr/local/git symlink.
This way, I can have /usr/local/git/bin in my PATH and I'm always using the latest version.
The latest version of this script also installs the man pages. You need to tweak your MANPATH to include the /usr/local/git/share/man directory.
Git Reset
Say you make a pull, merge it into your code, and decide you don't like it.
Use git-log, or tig, and find the hash of wherever you want to go back to (probably your last commit before the pull/merge) copy the hash, and do:
# Revert to a previous commit by hash:
git-reset --hard <hash>
Instead of the hash, you can use HEAD^ as a shortcut for the previous commit.
# Revert to previous commit:
git-reset --hard HEAD^
How do you set up a shared team repository?
How to set up a normal repository is described here -- but how do you set up a team repository that everybody can pull and push from and to?
Using a shared NFS file system
Assuming your team already has for instance a shared group membership that can be used.
mkdir /your/share/folder/project.git
cd /your/share/folder/project.git
newgrp yourteamgroup # if necessary
git init --bare --shared
To start using this repository the easiest thing to do is start from a local repository you already have been using:
cd your/local/workspace/project
git remote add origin /your/share/folder/project.git
git push origin master
Others can now clone this and start working:
cd your/local/workspace
git clone /your/share/folder/project.git
Using SSH
Set up a user account on the target server. Whether you use an account with no password, an account with a password, or use authorized_keys really depend on your required level of security. Take a look at Configuring Git over SSH for some more information.
If all developers use the same account for accessing this shared repository, you do not need to use the --shared option as above.
After initing the repository in the same way as above, you do the initial push like this:
cd your/local/workspace/project
git remote add origin user#server:/path/to/project.git
git push origin master
See the similarity with the above? The only thing that might happen in addition is SSH asking for a password if the account has a password. If you get this prompt on an account without a password the SSH server probably has disabled PermitEmptyPasswords.
Cloning now looks like this:
cd your/local/workspace
git clone user#server:/path/to/project.git
git status is your friend, use it often. Good for answering questions like:
What did that command just do?
What branch am I on?
What changes am I about to commit, and have I forgotten anything?
Was I in the middle of something last time I worked on this project (days, weeks, or perhaps months ago)?
Unlike, say svn status, git status runs nigh-instantly even on large projects. I often found it reassuring while learning git to use it frequently, to make sure my mental model of what was going on was accurate. Now I mostly just use it to remind myself what I've changed since my last commit.
Obviously, it's much more useful if your .gitignore is sanely configured.
Commit Changes
Once you've edited a file, you need to commit your changes to git. When you execute this command it will ask for a commit message - which is just a simple bit of text that tells everyone what you've changed.
$ git commit source/main.c
Will commit the file main.c in the directory ./source/
$ git commit -a # the -a flag pulls in all modified files
will commit all changed files (but not new files, those need to be added to the index with git-add). If you want to commit only certain files then you will need to stage them first with git-add and then commit without the -a flag.
Commiting only changes your local repository though not the remote repositories. If you want to send the commits to the remote repository then you will need to do a push.
$ git push <remote> <branch> # push new commits to the <branch> on the <remote> repository
For someone coming from CVS or SVN this is a change since the commit to the central repository now requires two steps.
How do you branch?
The default branch in a git repository is called master.
To create a new branch use
git branch <branch-name>
To see a list of all branches in the current repository type
git branch
If you want to switch to another branch you can use
git checkout <branch-name>
To create a new branch and switch to it in one step
git checkout -b <branch-name>
To delete a branch, use
git branch -d <branch-name>
To create a branch with the changes from the current branch, do
git stash
git stash branch <branch-name>
Getting the latest Code
$ git pull <remote> <branch> # fetches the code and merges it into
# your working directory
$ git fetch <remote> <branch> # fetches the code but does not merge
# it into your working directory
$ git pull --tag <remote> <branch> # same as above but fetch tags as well
$ git fetch --tag <remote> <branch> # you get the idea
That pretty much covers every case for getting the latest copy of the code from the remote repository.
The Pro Git free book is definitely my favorite, especially for beginners.
Git Magic is all you'll ever need. Guaranteed or your money back!
How do you merge branches?
If you want to merge a branch (e.g. master to release), make sure your current branch is the target branch you'd like to merge into (use git branch or git status to see your current branch).
Then use
git merge master
(where master is the name of the branch you want to merge with the current branch).
If there are any conflicts, you can use
git diff
to see pending conflicts you have to resolve.
I've also found Git Internals to be very useful. It is written by Scott Chacon (author of Pro Git, and maintainer of the Git Community Book). What I like about Git Internals is it focuses on the concepts first and then the commands, and being that it is ~100 small pages it is quickly digestible.
How do you see the history of revisions to a file?
git log -- filename
How to track remote branches
Assuming there is a remote repository that you cloned your local repository from and also assuming that there is a branch named 'some_branch' on that remote repository, here is how to track it locally:
# list remote branches
git branch -r
# start tracking one remote branch
git branch --track some_branch origin/some_branch
# change to the branch locally
git checkout some_branch
# make changes and commit them locally
....
# push your changes to the remote repository:
git push
A real good paper for understanding how Git works is The Git Parable. Very recommended!
How do you compare two revisions of a file, or your current file and a previous revision?
Compare command is git diff.
To compare 2 revisions of a file:
$ git diff <commit1> <commit2> <file_name>
That diffs commit1 against commit2; if you change order then files are diffed the other way round, which may not be what you expect...
To compare current staged file against the repository:
$ git diff --staged <file_name>
To compare current unstaged file against the repository:
$ git diff <file_name>
Why yet another howto? There are really good ones on the net, like the git guide which is perfect to begin. It has good links including the git book to which one can contribute (hosted on git hub) and which is perfect for this collective task.
On stackoverflow, I would really prefer to see your favorite tricks !
Mine, which I discovered only lately, is git stash, explained here, which enables you to save your current job and go to another branch
EDIT: as the previous post, if you really prefer stackoverlow format with posts as a wiki I will delete this answer
Console UI - Tig
Installation:
apt-get install tig
Usage
While inside a git repo, type 'tig', to view an interactive log, hit 'enter' on any log to see more information about it. h for help, which lists the basic functionality.
Trivia
"Tig" is "Git" backwards.
How can I create a branch on a remote repository?
Assuming that you have cloned your remote repository from some single remote repository.
# create a new branch locally
git branch name_of_branch
git checkout name_of_branch
# edit/add/remove files
# ...
# Commit your changes locally
git add fileName
git commit -m Message
# push changes and new branch to remote repository:
git push origin name_of_branch:name_of_branch
I got started with the official Git tutorial. I think it's practical enough for beginners (I was, and still am, a beginner, by your definition! I barely grasp makefiles, I've only played a bit with Apache Subversion, etc.).
How do I delete a branch on a remote repository?
Perform a push in your remote using : before the name of the branch
git push origin :mybranchname
being origin the name of your remote and mybranchname the name of the branch about to be deleted
http://help.github.com/remotes/
Push and pull changes
In an simplified way, just do git push and git pull. Changes are merged and if there's a conflict git will let you know and you can resolve it manually.
When you first push to a remote repository you need to do a git push origin master (master being the master branch). From then on you just do the git push.
Push tags with git push --tags.
Checking Out Code
First go to an empty dir, use "git init" to make it a repository, then clone the remote repo into your own.
git clone user#host.com:/dir/to/repo
Wherever you initially clone from is where "git pull" will pull from by default.
Gity: http://macendeavor.com/gity

How to backup an AOSP project on GitHub

I have an Android project composed of AOSP, and other code in an Ubuntu environment. As you know, I used git and its associated tool repo to download AOSP according to the procedures on android source site. Now I want to have a way of controlling the changes I make to the environment. I have read about Git, but perhaps not enough to know what is the best way to do this. Maybe I already have this capability just by using Git locally? So my question is: What is the best way to save state in my build environment please, and how do I save this on Github as a remote backup repository? I believe I need to have a .gitignor file to exclude object files? Basically I have a WORKING_DIRECTORY with all of my code in there. That directory has a .repo and .git directory in it.
You will find that most or all of your changes will be under certain branches. For me, I develop roms for the Nexus 9 so a lot of my changes are under device/htc/flounder. The common branch is frameworks/base/ where I also make a lot of changes.
To this end I have two separate git repos that store these:
https://github.com/seanashmore/frameworks_base
https://github.com/seanashmore/device_htc_flounder
To create these, I created a github account. Then went to each of he top level folders i.e. frameworks/base and device/htc/flounder and ran the command 'git init'. This initializes those directories as git repositories. You also need to create the repos on your github account, this will give you url's for you to 'push' your code to.
The initial push of frameworks/base will take some time as it is quite large, but once you have done that first push its very handy to keep track of your code changes and all the other benefits that git brings.
A very handy git guide can be found here: http://rogerdudler.github.io/git-guide/
If you need any more information or help just ask.

How to add Android-Project to GitHub [duplicate]

This question already has answers here:
How do you synchronise projects to GitHub with Android Studio?
(13 answers)
Closed 5 years ago.
I'm using Android Studio to code my apps. Now I want to work on 2 PC's and thought about using a Cloud-Service. I decided to use GitHub, but I can't find a way to synchronize my GitHub account with my Android Studio project...
Can anyone explain this to me ?
Best way to do this is probably through the good ol' command line. First, make sure you have git installed and in your path. You can get instructions from here.
Next, go to GitHub and create a new repository with a title and such. Instructions on that here. Don't worry about creating your first commit, we're going to do that on your local machine.
Now for the fun part.
Copy the repo link of your choice (I prefer ssh, but it depends on how far you went with the set up part) and head to the terminal.
cd ~/project-path-here
git init
git add .
git commit -am "initial commit"
git remote add origin <your link>
git push -u origin master
If all has gone well, you can reload the github page and see your new push.
On your other computer, you'll be able to clone down the repo you created.
cd ~/project-path-here
git clone <your link>
You can then use git pull and git push to retrieve and send changes to the server.
You can also look into Github's desktop application if you're on Windows or Mac for a simpler time, but I find these lack some more advanced features of git.
EDIT: To register your new git repo with Android Studio, Intellij, RubyMine, etc., go to the project settings (File->Settings), search for version control, and specify that your project is using git for version control. Here for more information on that. Once that is enabled, the VCS drop down will have more features. The ones to look at are Commit Changes (git commit and push) and Update Project (git pull).
Under the VCS tab in your Studio, there's on option to publish the project to Github. Will ask for your credentials, then you're good to go to push your code.
Just getting into Android app dev and I thought I might mention here that I think that we should gitignore the build folder. It's huge and it doesn't need to be repo'd
[Edit] I'm referring to the app/build folder. And hey I see it's not included in the Android Studio .gitignore

What is Repo and Why does Google use it?

When I wanted to get Android source code, I knew that I have to use "repo". So what is repo? Why do they use repo and not just use GIT?, and is there a GUI for repo that enables me to pause/resume syncing, because every time I get disconnected occasionally it seems that repo starts syncing from the beginning!
As is mentioned in the android webpage, repo does not replace git. It is just a tool over git and helps you to manage multiple git repositories.
For example, suppose I have a big project which has a lot of features and I have several teams working on each feature and I created one repository for each feature. For example suppose my repositories are wifi, telephony, power management, etc. This action has sense when your features have different life cycles. For example if I won't touch the wifi feature in my next release and but I will modify all the rest. So under this scenario, my project or product is distributed in several different git repositories.
So, to get a centralized photo of my project (one specific moment of my project, for example a milestone), I need to get the revision (git hash or tag) of each repository. Remember that we have one repository for each feature. Manually I could do it but could be very painful. So, with repo you can have one MANIFEST which links to all the revisions of each git repo (one for each feature) and have an specific picture of my whole project.
Simply, I could say that is a way to manage centralized multiple git repositories which are decentralized.
With repo you have more features, not only to checkout at a specific point. For more info go to http://source.android.com/source/using-repo.html.
Repo and git - what they are, what they are for - is explained on source.android.com
To work with the Android code, you
will need to use both Git and Repo.
Git is an open-source version-control system designed to
handle very large projects that are
distributed over multiple
repositories. In the context of
Android, we use Git for local
operations such as local branching,
commits, diffs, and edits.
Repo is a tool that we built on top of Git. Repo helps us manage the
many Git repositories, does the
uploads to our revision control
system, and automates parts of the
Android development workflow. Repo is
not meant to replace Git, only to make
it easier to work with Git in the
context of Android. The repo command
is an executable Python script that
you can put anywhere in your path.
There's no GUI for Repo, as far as I can tell, but there's quite a bit of guidance on the site above for controlling what Repo is doing from the command line.
Concerning the pause and restart point, whilst in a terminal window doing a repo sync you can hit, "ctrl + z" to pause the repo sync. To restart simply type "fg" into the same window.
Go to:
http://source.android.com/source/git-repo.html
and you can download the repo script. It is a Python script that uses the git command to do distributed source code revision.
After you have executed repo sync, do a ps -auwf to see the processes:
For mine I saw:
\_ python -E /sde3/root/download/android/android/.repo/repo/main.py --rep
\_ git fetch korg
\_ git fetch korg
\_ git index-pack --stdin -v --fix-thin --keep=fetch-pack 5227 on
Yes, repo sync breaks often. But it is robust, just restart the command and it will resuming syncing again - those that have been updated will not be re-applied, so it will skip over them and continue with the rest.
repo sync has various useful options:
-f recovers from disconnects
-c just uploads the branch you asked for
-j <#CPUS> speeds up the sync by increasing the number of cpus used by the command

How to use Git on Android?

I have a desktop application using git for synchronization. I have also an android application which do the same as the desktop, but I don't know how to do the synchronization part on it. I haven't found any implementation of git on android. I found a jgit, but its unwell documented and I was not able to do even a commit with that.
I was thinking about remote commands to my git server from my android app, but this is really a tease for me.
Could you tell me if any other git implementation which can be used on android exists? If you have any idea how to solve that, please tell me.
Since this question was first posted, an Android app has been added to the market that can checkout Git repos, called Agit. It can't commit or push yet, but the clone/fetch/pull functionality is useful. The other issue is that a patched version of ConnectBot needs to be installed before Agit if you want to use SSH keys. If you already have ConnectBot, uninstall it first. I did not do this and ran into problems.
Edit: As of April 2021, the ability to push and pull has been added, however, it does seem to be very buggy as I have only been able to pull changes, but never push them.
Another option is using ASE. There seems to be a full-featured pure python implementation of git at https://github.com/jelmer/dulwich.
You can install https://github.com/termux/termux-app # https://play.google.com/store/apps/details?id=com.termux, then you just need to open the terminal and type:
apt update
apt install git
If the device is rooted, you can also use debian's debootstrap ( http://wiki.debian.org/Debootstrap ) application to create a debian/armel image, mount it in your android device and chroot to it, you have aptitude here so any package available for armel can be installed on your device (to install git: aptitude install git). Look here for information on how to install debian for your android: http://lanrat.com/install-debian-on-android/
Some other solutions that are now available, besided Agit, since this question was last answered:
A git & mercurial client for bitbucket called Bitbeaker
A git app from github
The Android Java IDE AIDE also has git functionality, so you can download from a git directory and if its an Android app modify and run it aswell.
You can also try Pocket Git: https://play.google.com/store/apps/details?id=com.aor.pocketgit
Pocket Git supports SSH (with passphrases, but private keys seem to have some issues) and HTTP, cloning, stage, unstage, commit, push and pull; create, delete and merge branches; and it also has a graphical log viewer and can show diffs.
Disclaimer: I'm the developer
A lot of already existing apps have been posted in the answers, but following links might be useful for those looking for their own implementation:
libgit2
This is a pure C implementation that claims to be highly portable. And the project also describes how to compile the sources for android platform. Now what needs to be done is to write a JNI binding for it. Even an executable binary would be sufficient in some cases.
HTTP (dumb) protocol
As an alternative, if one's purely interested in read operations from a repository, this protocol can be implemented over HTTP. There is also a smart protocol which depends on ssh and does differential transfers.
JGit Core Sources
Using just the core package from its sources. All the javax.* dependencies and other incompatible/alien classes will needed to be replaced with android alternatives though. But worth the effort if a pure Java implementation can be ported to android.
I would suggest to take a look at Gidder. It's Git server implementation for Android with user and repository management and also support dynamic DNS. You can easily store your code in your Android device and access using a WiFi connection.
MGit is the successor of SGit, and it works very well for me.
Update:
Comment underneath this answer by OP- (Nathan Osman)
unfortunately, I was forced to pull the application after some recent policy changes on the Play Store that required publishers to have their address displayed on the application's store page.
Original Answer
I've just (circa April 2013) published an app on the Play store named GitDroid. The application allows you to do the following:
clone remote repositories
pull from the remote and merge new revisions
view commits and browse files
The app cannot push to a remote or make local commits yet - this is planned for a future update.
This is how I would do it:
Well you likely want to define an interface for your synchronization needs.
You implement this interface in C for both desktop and android device (with the help of the NDK) by making the implementation use git (native).
Then, for the Android app, you code a JNI layer on top so that it exposes the interface to Java.
The tricky part would be to have the different git commands compile for Android: you'll have to rewrite makefiles.
Try SGit, it can commit & push over SSH with pssphrase-less keys and it is available on F-Droid. It is built on top of JGit. It is not perfect (yet) and JGit implementation is not as good as original Git, but looks usable.
You can install git on android with Termux. Just install from Play Store and run the command:
pkg install git
Reference: https://mvprepublic.com/blog/2020/04/08/how-to-run-git-on-android-devices/
Update: CubeGit has been removed because of changes inside the Android system and missing time / incentives to update.
Please pick one of the alternatives.
One more option is was CubeGit.
We have released CubeGit on Google Play a few days ago.
It is an interface to a cross compiled git binary and also supports local commits and push via ssh/http/https.
JGit - http://eclipse.org/jgit/

Categories

Resources