Android Studio Git configuration is relatively simple, it is possible the problems appeared in the middle of trouble. If you want to know or are interested, please read on.
First you have to download Git client, the URL: http: //git-scm.com/download/.
According to need to download the appropriate version, and install it. Then specify git.exe in Android Studio, click "Test", the following tips will pop success.
Since I use Android Studio 2.0 Preview, does not exist prompted "Enable Version Control Integration", causing me to look for a long T ~ T. In fact, there is a similar operation.
Is the "Create Git Repository", otherwise you will always get "... such that source detected in git but Unregistered Vcs root detected" prompt.
This is done, git down it is to add a remote. I use open source code hosting Chinese online first to get an address: https: //git.oschina.net/***.git.
Open git base, and switch to the project's root directory, enter the following command
git remote add origin https://git.oschina.net/***.git
Hopefully this step is complete.
Then git add operations In Android Studio.
It followed commit directory, and finally push the code to the remote repository.
At this point, the end of the submission.
By default, the project will have Android Studio of these folders:. Build, libs, src, but each time you submit the code to git, will be prompted to build a file folder in the many required to submit, in fact, we do not care about build file folder changes the situation. How to do it? .gitignore Use it to filter out.
Establish .gitignore file in the root directory of the project, and then add
It's that simple! If you want to filter other files, add the corresponding rule on it.
After saving .gitignore file, you need to run the following command to submit .gitignore file to the git.
git rm -r --cached.
git commit -m "Add .gitignore File"
git push origin master
"Git rm -r - cached in a directory," this command is a little hard, will target directory empty, - cached (Note: This means that all of the files, there is a point); "git add.", Then. all the file back to the cache (stages new and modified, without deleted). If you currently have the latest and the other documents already push to a remote repository, you can use add .gitignore trouble.
In addition, you can use the following command instead of git rm -r --cached.
git add -A
Represent stages All. Novice may not understand. Well, I start with the git in three states and file conversion.
1. First, I created a git test.txt in the corresponding project directory and enter the following string and save it.
2, open git bash, enter the command git status, view the file status
You will see red test.txt be submitted in the state, the file is marked as Untracked files, and suggest you use git add ... command file that contains the list to be submitted.
3. Follow the prompts, use the command git add test.txt, this file is added to the git snapshots, git status again
At this time test.txt state became Changes to be committed, waiting to be submitted. It also prompts you to then use git reset HEAD ... can be reduced to the status of the file buffer status, that status back Untracked files.
4, open test.txt, to which add some content, save.
In fact, the more the world this string. Check again with git status file status.
In addition to the previous "Changes to be committed" state, but also more "Changes not staged for commit" state indicates that the file has been modified, but the modification has not been placed in the staging area, which is not a snapshot. If the commit operation at this time will only submit "Hello", ignore the "world".
When prompted, if you want the latest changes "Hello world" into the repository, you need to use the command git add test.txt again; if you want to undo changes that just submit "Hello", you can use git checkout - test.txt, again git status, you can see the status has changed.
Summary: So, before the file is not ready to commit, the presence of three states:. Untracked files, Changes not staged for commit, Changes to be committed to each state can be freely converted.
In subsequent versions of git, add the git stage git add as a synonym, so semantically more in line with the above Changes not staged for commit. Why do you want to increase the stage?
1, submitted in batches, commit to reduce particle size.
2, file snapshots to facilitate rollback.
If you commit too many files on the subsequent rollback or follow-up is undoubtedly very bad, the problem is not locate it, experienced a clear estimate. For example, you do two functions A and B, the corresponding file modifications are a1.java, a2.java; b1.java, b2.java, when it can be submitted to:
git stage a1.java a2.java
git commit -m "function A"
git stage b1.java b2.java
git commit -m "function B"
At the same time, each modified stage, at any time, you can return to the previous staged states:
git checkout - test.txt
If you want to delete from the stage, use the reset
git reset test.txt
This command is git stage test.txt inverse operation.