Git basis
This blog is my learning based on network video notes, more practical, it can help you quickly become familiar with Git and GitHub.
Article Directory
- Git basis
- First, acquaintance GitHub
- 1.1 What is Git
- 1.2 What is a version control system
- Specific features 1.3 version control system
- 1.4 What is GitHub?
- 1.5 GitHub and Git the difference
- Second, the use GitHub
- 2.1 The purpose of GitHub
- The basic concept of the 2.2 GitHub
- 2.3 Creating a warehouse / create a new project
- 2.4 Warehouse Management
- Practice 2.5 GitHub basic concepts
- 2.5.1 GitHub Home
- 2.5.2 profile
- 2.5.3 Collection (Star)
- 2.5.4 Watch (Watch)
- 2.5.5 replicable cloning project (Fork)
- 2.5.6 initiating a request (Pull request)
- 2.6 open source project contribution to the process
- Three, Git basic concepts
- Four, Git initialization and warehouse creation and manipulation
- 4.1 Git basic settings
- 4.2 initialize a new Git repository
- 4.3 View File Status
- 4.4 documents submitted to the staging area
- 4.5 documents submitted to the staging area warehouse
- 4.6 Delete file repository
- 4.6.1 Delete the working directory files
- 4.6.2 delete staging area file (do not use)
- 4.6.3 need to commit operation after deleting files
- 4.7 View remote repository of information associated with a local warehouse
- 4.8 remote host name
- Add file 4.9 Ignore
- Five, Git remote repository management
- 5.1 The purpose remote repository
- 5.2 git clone operation
- 5.3 synchronized to the local repository GitHub
- 5.3 .1 command submitted to the distal end
- 5.3.2 local warehouse using HTTPS synchronization error solutions
- 5.3.3 Git SSH using a synchronization code to GitHub
- 5.3.3.1 generate SSH keys
- 5.3.3.2 SSH key input to GitHub
- 5.3.3.3 establish a connection and a distal end
- 5.3.3.4 Connection error and a distal end
- 5.3.4 git push submitted wrong solution
First, acquaintance GitHub
1.1 What is Git
Git is a free, open-source version control software
1.2 What is a version control system
版本控制系统是一种**记录一个或若干个文件内容变化,以便将来查阅特定版本修改情况的系统。**
Specific features 1.3 version control system
-
All change history log files
-
At any time to restore any historical status
-
Multiplayer collaborative development or modification project
-
Recoverable error
1.4 What is GitHub?
GitHub is the world's largest social programming and code hosting site
GitHub hosts git repository, and provides a web interface (user name .github.io / warehouse name)
1.5 GitHub and Git the difference
- GitHub and Git are two completely different things
- In Git, developers will be stored in the source code
Git 仓库
of the library and use them - GitHub Git repository is to provide a service on the network
- Open software source code on GitHub all managed by Git
Second, the use GitHub
2.1 The purpose of GitHub
With GitHub hosting project code
The basic concept of the 2.2 GitHub
a. warehouse (Repository)
Warehouse used to store program code and each item corresponds to a warehouse , a plurality of the open source projects a plurality of warehouses.
b. Collection (Star)
Collection project, you can easily view the next time.
c. Copy the cloning project (fork)
When viewing others items, if you want to save the project to their own warehouses, can be cloned copy of the project, to our account.
** Note: ** independent existence when the fork of the project.
d. initiation request (Pull Request)
I copied someone else's library, I made changes, I change the library, but the library is copied people did not change. At this point, you can select the pull request, a request to the owner of the library. If the author agrees that door I write code that will be incorporated into the original warehouse.
e. Watch (Watch)Watch an item, then the future of this project there are any updates, my door will be notified.
f. thing card (Issue)
Find the code BUG, but there is no molding code, need to be discussed.
2.3 Creating a warehouse / create a new project
Description:
- A Git repository corresponds to an open source project
- By git git repository management
2.4 Warehouse Management
2.4.1 New File
2.4.2 Editing files
2.4.3 deleting files
2.4.4 GitHub Issues
Role: find the code BUG, but there is no molding code, need to be discussed; or use open-source projects use problems.
Scenario: Joe Smith John Doe found in open-source git repository, then submit an Issue; the next day, John Doe Log Home GitHub see notifications, and Joe Smith exchange, and finally close the Issue.
Practice 2.5 GitHub basic concepts
2.5.1 GitHub Home
2.5.2 profile
2.5.3 Collection (Star)
2.5.4 Watch (Watch)
2.5.5 replicable cloning project (Fork)
2.5.6 initiating a request (Pull request)
2.6 open source project contribution to the process
- New issue
- Submit issues that have arisen or suggestions or ideas
- Pull request
- fork project
- Modify their warehouse project code
- New pull request
- Waiting for the operation of the (consolidated)
Three, Git basic concepts
3.1 Git workflow
3.2 Git three partitions
3.3 View submission history
git log [分支名]
View submit a branch of history, do not write the name of the branch to see where the current branchgit log --oneline
Line shows the commit historygit log -n
Where n is a number, see the recent submission of ngit log --author [贡献者名字]
View designated contributors submit recordsgit log --graph
Graphic method displays commit history
3.4 version rollback
- First execution
git reset --soft HEAD^
undo a recent submission, would be restored to modify the staging area.--soft
It means a soft return, as well as the corresponding--hard
hard return- HEAD ^^ submit two of said withdrawal, withdrawal may be abbreviated as n times HEAD ~ n
- After a soft return submitted to the
git branch -avv
command to view the information branch
Four, Git initialization and warehouse creation and manipulation
4.1 Git basic settings
Using Git first thing is to set the name and email, this is the time of submission commit
签名
.
git config --global user.name "annjeff"
git config --global user.email "[email protected]"
git config --list
View Settings
After executing the above command, your home directory (home directory) to establish a call ~/.gitconfig
. File content is generally as follows:
[user]
name = annjeff
email = [email protected]
4.2 initialize a new Git repository
- Create a new folder at any position, right click and choose Git Bash
- Use git init command to initialize the folder
4.3 View File Status
Use
git status
command, you can view the file status
4.4 documents submitted to the staging area
git add fileName
4.5 documents submitted to the staging area warehouse
git commit -m "描述信息"
4.6 Delete file repository
4.6.1 Delete the working directory files
rm -f fileName
4.6.2 delete staging area file (do not use)
git rm -r --cached 'fileName'
Accidentally deleted files, not executed before the commit, you can use the following code to recover:
git reset HEAD "fileName"
git checkout -- "fileName"
4.6.3 need to commit operation after deleting files
git commit -m '提交描述'
4.7 View remote repository of information associated with a local warehouse
git remote -v
4.8 remote host name
Git requirements for each remote host associated local repository must specify a host name (the default is Origin) , for their own local warehouse to identify the associated host
git remote
command for the host associated with the management of the local repository, a local repository can be associated any number of hosts (ie remote repository) . Cloning a remote repository to a local, you can also use the-o
option to modify the host name, address plus a field behind a local repository home directory name
Add file 4.9 Ignore
If you hope git automatically ignore some files, you can create a
.gitignore
document, the expression automatically ignore some files through some positive.
Example 1: Ignore the current project at .o 或 .a
the end of the file
*.[oa]
Example 2: to ignore ~
files ending
*~
Some pattern-matching rules
- Blank lines or lines starting with ** # ** automatically ignored
- You can use the standard
glob
pattern matching - Pattern matching may be (/) begins, to prevent recursion
- Pattern matching can end (/), the directory specified
- You can use **! ** Ignore the beginning of a pattern
Five, Git remote repository management
5.1 The purpose remote repository
Backup, code-sharing, centralized management
5.2 git clone operation
5.2.1 Objective
The remote repository (GitHub corresponding item) to a local
5.2.2 Using the code repository clone
git clone 仓库地址
git clone https://github.com/Annjeff/test.git
5.3 synchronized to the local repository GitHub
5.3 .1 command submitted to the distal end
git push
5.3.2 local warehouse using HTTPS synchronization error solutions
5.3.3 Git SSH using a synchronization code to GitHub
5.3.3.1 generate SSH keys
SSH key generation command:
ssh-keygen -t rsa -C 任意邮箱
whereinrsa
encryption algorithm
5.3.3.2 SSH key input to GitHub
At this point we already know GitHub
公钥
what it is, no need to enter a user name and password, you can communicate directly and server security.
5.3.3.3 establish a connection and a distal end
And establish a connection to a remote repository:
git remote add origin [email protected]:annjeff/The-Note-of-Annjeff-for-Interview.git
5.3.3.4 Connection error and a distal end
- If there is: fatal: remote origin already exists
Use the command git remote rm origin, and then perform a git remote add origin Project Address
The local push to a remote repository:git push origin master
5.3.4 git push submitted wrong solution
git push 出现:rejected master -> master(non-fast-forward)
Solution one: [Recommended] The use of forced cover, alternate content repository git native code
git push -f origin master
Solution two: first to a local git code fetch, then merge, the final push
git fetch
git merge