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
- $sudo apt-get Install git
- $sudo Apt-get Install Git-core
Update git
[Plain]View PlainCopy
- $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
- $mkdir android4.2
- $CD android4.2
- $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
- $cd. Git
- $vim Config
The original contents of the configuration file are:
[Plain]View PlainCopy
- [Core]
- repositoryformatversion = 0
- FileMode = True
- Bare = False
- Logallrefupdates = True
Include the following in the configuration file:
[Plain]View PlainCopy
- [Receive]
- 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
- $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
- $touch Spec.txt
- $git Add Spec.txt
- $git commit-a-M "First commit"
- $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
- $mkdir download/myprojects
- $git Clone/data/downloads/git/android4.2/.git
Modify a file
[Plain]View PlainCopy
- $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
- $git Add Test.text
- $git commit-a-M "Second commit"
- $git Push Origin Master
View log Information
[Plain]View PlainCopy
- $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
- $CD android4.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"