Git Basic Application

Source: Internet
Author: User
Tags git clone repository

Git Learning

1. Git tool basic meaning

The biggest use of git is to record changes to each version, compare the differences between each version, and maintain and develop the same project by multiple people. Supports version rollback.

2. Git basic commands

A. Create a version Library

   $ Mkdir learngit // create a directory

$ CD learngit // enter the directory $ PWD // view the current directory/users/Michael/learngit

$ Git init // create a local version Library
  Initialized empty Git repository in /Users/michael/learngit/.git/

$ Git add readme.txt // Add readme.txt to the Workspace
$ Git commit-M "test" // submit readme.txt to the local repository
$ Git status // check that no file has been submitted to the repository in the current workspace.
$ Git diff readme.txt // check the changes made to the repository before submission (only before submission to the repository)
$ Git log // view history
$ Git log -- pretty = oneline // display historical records on a row
$ Git reset -- hard head ^ // roll back to the previous version (
$ Git reset -- hard head ^ indicates to roll back to the previous version.)
$ Git reset -- hard version code // roll back to the version number represented by the version code (use $ git log to view the version code)
$ Git reflog // display each command after the operation, including the rollback version. It is generally used to check the version number before the rollback when the rollback is regret, and then use $ git reset -- hard version number, to return to the version before the rollback.
$ Git diff head -- readme.txt // The Difference Between the readme.txt work zone and the readme.txt in the slave Database
$ Git checkout -- readme.txt // the latest version of readme.txt is removed. If there is no $ git add, the last version that has not been modified will be returned. If it has been changed only after $ git add, returns to the status of $ git add.
$ Git reset head readme.txt // roll back redme.txt from the temporary storage area to the work area, and then use $ git checkout -- readme.txt to discard the workspace Modification
$ Git RM readme.txt // Delete readme.txtfrom the repository before using this command. After you use the RM readme.txtcommand to delete readme.txt, you can use $ git checkout -- readme.txt to retrieve the file. $ Git checkout -- readme.txt is actually replacing the version in the workspace with the version in the version Library)
  
$ Ssh-keygen-t rsa-c "[email protected]" // create a local SSH key for binding the key of the GitHub website, that is, let the GitHub server know that this host is associated with your GitHub account, and fill in your email address (after creation, there will be at the root directory. the SSH folder contains two files: id_rsa and id_rsa.pub. id_rsa.pub is the public key to be bound to the GitHub website)
  
$ Git remote add origin [email protected]: Mingming/learngit. Git // associate it with the repository on the remote GitHub server. Remember[Email protected]: replace Mingming/learngit. Git with the address of your repository.
  
$ Git push-u origin master // push the content to the remote repository and associate the local master branch with the remote master Branch (First push and Use)
$ Git push origin master // push the local master branch to the remote master Branch (Use this command directly after modification)
$ Git clone
[Email protected]: Mingming/learngit. Git // clone from a remote repository to directly populate the local New Repository
$ Git checkout-B Dev // create a Dev branch and switch to the dev Branch
$ Git branch Dev // create the dev Branch
$ Git checkout Dev // switch to the dev Branch
$ Git branch // list all branches
$ Git merge Dev // merge the work of the dev branch to the current Branch
$ Git branch-D Dev // Delete the dev Branch
  
$ Git log -- graph -- pretty = oneline -- abbrev-commit // view the branch merge graph.
  
$ Git merge -- no-FF-M "merge with no-FF" Dev // disable Faste forword to merge branches. after merging, you can view the merged branches in history, faste forword is not displayed in the history.
$ Git stash // Save the workspace. (when a temporary task needs to be modified, You need to pause the task above the branch)
$ Git stash list // view the site list of the current Branch
$ Git stash apply // resume the work site of this branch
$ Git stash drop // Delete stash content
$ Git stash pop // restore the stash content of the current branch and delete the stash
  
$ Git stash apply [email protected] {0} // restore the specified stash
$ Git branch-D Dev // force Delete Dev Branch
$ Git remote-V // view remote database details
  
$ Git checkout-B Dev origin/dev // create a local Dev branch,
  
$ Git Branch -- Set-upstream Dev origin/dev // specify local Dev and remote Association
$ Git tag V1.0 // tag the version number of the current branch V1. use this tag to mark your version.
$ Git tag // view all tags
$ Git tag V1.0 444444 // tag a version number whose commit ID is 444444
$ Git show V1.0 // View Details of V1.0
$ Git tag-A V1.0-M "Shuo Ming Xin Xi" // tag and label description
$ Git tag-D V1.0 // Delete the V1.0 tag
$ Git push origin V1.0 // push the V1.0 tag
$ Git push origin tags // push all tags
  
$ Git push origin: refs/tags/V1.0 // delete a remote tag (before this, you must delete the local tag V1.0)
  
3. Git usage skills
A. The remote warehouse can fork others' projects and then clone them to the local for secondary development.
B. You can write a. gitignore file to ignore some of the files when they are added to the workspace.
C. two people, or one person, modify the same piece of code on two computers. When one party pushes the code to a remote device and the other party pushes the code, git pull is required to update the local repository, then, you can view the conflict between the two parties and push the conflict to the remote device only after the conflict is modified again.
D. Build a git Server
.
$ Sudo apt-Get install git // install git software on the server
.. $ Sudi adduser git // create a git user to run the GIT service.
... Collect the public keys (
In the id_rsa.pub file), Import all users' public keys to the file/home/git /. SSH/authorized_keys, one row, // This file can be used when the number of users is small, and gitosis can be used for management when the number of users is large
...
$ Sudo git init -- bare sample. Git // enter this command in the directory selected as the repository and an empty repository named sample. Git will be created.
....
$ Sudo chown-r git: git sample. Git // change the owner to git.
..... For security reasons, the created git user is not allowed to log on to the shell
Git: X: 1001: 1001:,:/home/git:/bin/bash changedGit: X: 1001: 1001:,:/home/git:/usr/bin/Git-shell, so that git users can use SSH links, but cannot use shell Login
...... Used on the computers of the respective users
$ Git clone [email protected]:/srv/sample. Git clone repository is OK
  

Git Basic Application

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.