Git admin Local code (a) "Go"

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/weihan1314/article/details/8677800

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Directory (?) [+]

Install Git

[Plain]View PlainCopy
    1. $sudo apt-get Install git
    2. $sudo Apt-get Install Git-core
Update git

[Plain]View PlainCopy
    1. $git Clone Git://git.kernel.org/pub/scm/git/git.git
After you install git, the git command prompts you to confirm that Git is installed successfully.

Initializing the Code Warehouse

[Plain]View PlainCopy
    1. $mkdir android4.2
    2. $CD android4.2
    3. $git Init

The specific differences between git init and git--bare init reference: http://blog.haohtml.com/archives/12265

Tip: Initialized empty git repository in/data/downloads/git/android4.2/.git/proves that the Git repository (repository) was created successfully config config file (global)

[Plain]View PlainCopy
    1. $cd. Git
    2. $vim Config
The original contents of the configuration file are:

[Plain]View PlainCopy
    1. [Core]
    2. repositoryformatversion = 0
    3. FileMode = True
    4. Bare = False
    5. Logallrefupdates = True
Include the following in the configuration file:

[Plain]View PlainCopy
    1. [Receive]
    2. Denycurrentbranch = Ignore
The purpose of joining this configuration is to allow the use of Git push to submit code to the server, otherwise the following exception will occur:

remote:error:refusing to update checked out Branch:refs/heads/master

Remote:error:By default, updating the current branch in a Non-bare repository

Remote:error:is denied, because it'll make the index and work tree inconsistent

Remote:error:with What do you pushed, and would require ' git reset--hard ' to match

Remote:error:the work tree to HEAD.

Remote:error:

Remote:error:You can set ' receive.denycurrentbranch ' configuration variable to

Remote:error: ' Ignore ' or ' warn ' in the remote repository to allow pushing into

Remote:error:its Current Branch; However, this isn't recommended unless you

Remote:error:arranged to update their work tree to match the what's pushed in some

Remote:error:other.

Remote:error:

Remote:error:To squelch This message and still keep the default behaviour, set

Remote:error: ' receive.denycurrentbranch ' configuration variable to ' refuse '.

to [email protected]:/var/git.server/.../web

! [Remote rejected] master, master (branch is currently checked out)

Error:failed to push some refs to ' [email protected]:/var/git.server/.../web '

Create a description document in the Code warehouse (the document can be created casually)

[Plain]View PlainCopy
    1. $touch Spec.txt
Note: If the initial code warehouse is empty, Git push Origin master commits the code with the following exception:

ERROR:SRC Refspec Master does not match any.
Error:failed to push some refs to '/data/downloads/git/android4.2/.git
So we need to create a file in the repository after the code warehouse is initialized:

Instance:

[Plain]View PlainCopy
    1. $touch Spec.txt
    2. $git Add Spec.txt
    3. $git commit-a-M "First commit"
    4. $git push
At this point, the basic code warehouse has been created. The Git repository for the local code warehouse is:/data/downloads/git/android4.2/.git

Synchronizing code

Create myprojects directory, synchronize code

[Plain]View PlainCopy
    1. $mkdir download/myprojects
    2. $git Clone/data/downloads/git/android4.2/.git
Modify a file
[Plain]View PlainCopy
    1. $touch Test.txt
(Note: Here you can write and change the file, this article only explains the use of the Git library, so simply create a file)

Use the Git diff and git status commands to see the current state of your code

Submit Code

[Plain]View PlainCopy
    1. $git Add Test.text
    2. $git commit-a-M "Second commit"
    3. $git Push Origin Master
View log Information

[Plain]View PlainCopy
    1. $git Log

To see if the code in the Code warehouse is committed successfully

Enter the code warehouse directory to view the code submission log

[Plain]View PlainCopy
    1. $CD android4.2
    2. $git Log
Can see the log information submitted by the Code, but can not see the code we submitted, what happened?

If git init initialization is used, the directory of the remote repository also contains the work tree, and when the local repository is push to the remote repository, if the remote warehouse is on a push branch (no problem if it is not in the push branch at that time), The result of the push will not be reflected on the work tree, which is the corresponding file in the remote repository directory or the previous content.

Use the following command to view submitted content
$git Reset--hard

Fallback to the current latest (local latest) submitted code information

Git admin Local code (a) "Go"

Related Article

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.