The use of Git

Source: Internet
Author: User
Tags git workflow

As an entry-level novice, learning to use git to manage your own code is an essential step in the ladder. The GitHub account was registered very early, but there was nothing written about it, and the intern's department architect began to standardize the code for the program, requiring documentation, and the version control tool intended to switch from SVN to git. I also want to participate in the translation of Elasticsearch official documents, learning Git is imminent!

1. Apply for a GitHub account

2. Install Git for Windows. https://git-for-windows.github.io/(Good-bye download Slow)

3.git Configuration

Open git bash

View configuration information: Git config--list

Configuration command: Git config--global user.name/core.editor/merge.tool

4.git Workflow (understanding)

It feels like SVN.

4.git Basic Concepts

Head is a "cursor" to the master branch, and the object indicates the Git object library.

When you execute git add after the workspace is modified, the staging area tree is updated, the modified file is written to the object library in the new object, and the ID of the object is recorded in the staging area file index.

When you perform a commit operation Git commit, the staging area directory tree is written to the object library, and the master branch points to the staging area directory tree at the time of submission.

When you execute git reset head, the staging area tree is rewritten and replaced by the directory tree that master refers to, but the workspace is unaffected.

When executing git rm--cached <file>, the file is deleted directly from staging area and the workspace does not change

Git checkout. The workspace file is replaced with staging area all or the specified file. Make sure that the workspace is not added to the staging area changes.

Git checkout HEAD. Replaces the files in the staging area and workspace with all or the specified files in the master branch that head points to.

5. Create a warehouse (with a. Git subdirectory)

Create a warehouse in the current directory and add a commit file

Git init newrepo

git add *.c

git add README

Git commit-m ' coments '

Copy items from the Git repository

git clone <repo> <directory> newname

6.git Basic Operation

git status [-s]

Green font A For add, M for Modified,r on behalf of RENAME,D representative Delete (git rm)

Git diff

git diff--cached

git diff HEAD

Git diff-stat

Git commit-m ' coments '

Git commit-a skip git add

Git reset HEAD cancels the cached content

git rm removed from cache

git rm--chched is removed from the cache but retains files in the workspace

git MV renaming files

7. Git branch management (GIT's mandatory kill feature, separated from the main line, does not affect the main trunk and continue to work)

Git branch (branchname) to create a branch

Git checkout branch switch to branch git checkout-b (branchname) to create a branch and immediately switch to that branch

Git merge Merge Branch

Git branch lists Branches

Git branch-d (branchname) Delete Branch

Git merge Branch merge to Main branch (replace?) )

After git manually resolves the conflict, use git add to tell git that the file conflict has been resolved

Last Git commit

8.git Log

git log View commit history

Git log--oneline simple version history

git log--oneline--graph

git log--reverse--oneline

git log--author

Git log-- oneline --before={3.weeks. AGO}--After ={ - --- Merges

9. Git tag (always remember that special snapshot)

git tag -a v1. 0

10. Remote Repository GitHub

Http://www.runoob.com/git/git-remote-repo.html

11.git Server Setup

GitHub doesn't want to let others see your project for a fee, so the company needs to build a git server to use as a private repository.

Http://www.runoob.com/git/git-server.html

The use of Git

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.