Android Studio configuration git and git file status description

Source: Internet
Author: User

Android Studio configuration Git is still relatively simple, the trouble is that there may be a variety of problems in the middle. If you want to know or are interested, please look down.

First you have to download the git client, url: http://git-scm.com/download/.

Download the appropriate version as needed and install it. Then specify Git.exe in Android studio, click "Test", then the following prompt will pop up.

Because I use Android Studio 2.0 Preview, there is no "Enable Version Control integration" hint, I found a half-day t~t. Actually, there is a similar operation.

This is the "Create Git Repository", otherwise you will always get "... such that source detected in Git but unregistered Vcs root detected" prompt. To show the unregistered roots above the two projects completed the configuration.

This is done, and the next step is to add a remote to git. I use open source China online code hosting, first get an address: https://git.oschina.net/***.git.

Open git base and switch to the root of the project and enter the following command

Git remote add origin https://git.oschina.net/***.git

If it goes well, this step is complete.

Then do the git add operation in Android Studio.

Next is the commit directory, and finally the push code to the remote repository.

At this point, one commit is completed.

By default, Android Studio projects will have these folders: Build, libs, SRC. But every time you commit the code to git, you'll be prompted for the many files in the build folder that need to be submitted, but we don't really care about the file changes in the build folder. What do we do? Use. Gitignore to filter it out.

Build the. gitignore file in the project root directory, and then add

Build

It's so easy! If you want to filter other files, add the appropriate rules to it.

After you save the. gitignore file, you also need to run the following commands to commit the. gitignore file to Git.

Git rm-r-M "Add. gitignore file"git push Origin master

"Git rm-r--Cached a directory", this command is a bit malicious, will be the target directory empty,--cached. (Note: This represents all the files, there is a point); "Git Add." And then re-add all the files to the cache (stages new and Modifi Ed, without deleted). If your current other file is already up-to-date and has been push to the remote repository, you can use Add. Gitignore.

In addition, you can use the following command instead of Git rm-r--cached.

Git add-a

Represents stages all. The novice may not be quite sure. OK, I'll start with the three file states and their transitions in git.

---------------------------------------------------------------------------------------------

Gorgeous divider Line

---------------------------------------------------------------------------------------------

1. First, I create a test.txt in the corresponding project directory of Git, and enter the following string and save it.

Hello

2. Open git bash, enter command git status, view file status

You will see that the red Test.txt is in the pending state, this file is marked as untracked files, and it is recommended that you use git add <file> command to include the file in the pending manifest.

3, follow the prompts, use the command git add test.txt, add this file to Git snapshot, git status again

At this point the Test.txt state becomes changes to be committed, waiting for submission. Then at the same time it also prompts you to use git reset HEAD <file> You can restore the file state to a staging state, or back to the untracked files state.

4, open test.txt, add some content to it, save.

Helloworld

In fact, the world is the string. Use git status again to view the file status.

In addition to the previous "changes to be committed" state, there is a "changes not staged for commit" state, indicating that the file has been modified, but that the modification has not been placed into the staging area, that is, no snapshot was generated. If a commit is committed at this point, only "Hello" is submitted and "world" is ignored.

According to the prompt, if you want to submit the latest modification "Hello World" to the repository, you need to use the command git add test.txt again, if you want to undo the change, just want to commit "Hello", you can use git checkout-test.txt, Git again Status, you can see that the state has changed.

Summary: Therefore, there are three states before a commit operation of a file: untracked files, changes not staged for commit, changes to is committed. Each state can be converted at will.

--------------------------------------------------------------------------------------------------------

Off Topic

--------------------------------------------------------------------------------------------------------

In later versions of Git, git stage was added as a synonym for git add, which semantically conforms to the above changes not staged for commit. Why do you want to add the stage?

1, batch submission, reduce the granularity of commit.

2, file snapshot, easy fallback.

If you submit too many files at one time, the subsequent rollback or follow-up is no doubt very unfavorable, the location of the problem is also inconvenient, experienced estimates clearly. For example, you have done two functions A and B, the corresponding file modification is A1.java, A2.java; B1.java, B2.java, you can do this when you submit:

-M "Function a"
-M "Function B"

At the same time, each time you modify the stage, you can go back to the last staged state at any time:

Git checkout--test.txt

If you want to remove from the stage, use the Reset

git reset test.txt

This command is the inverse of git stage test.txt.

Reference: Know-why git add before git commit?

Android Studio configuration git and git file status description

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.