Git basic operations

Source: Internet
Author: User
Tags install perl

Git basic operations

Git clone [-B branch name] chenlong @ http: // project/admin. git

Default master branch without-B Parameter

Git clone http: // project/admin. git
Git clone-progress-v http: // project/admin. git

Git.exe clone-progress-v "http: // project/admin. git" "\ 192.168.0.105 \ www \ other_user \ chenlong \ admin"

Settings-> git edit local. git/config add
[Credential]
Helper = store

Git clone @ http: // project/admin. git admin2

Git checkout-application/core/MY_Exceptions.php

Git reset HEAD (commit) file

Git reset-hard HEAD ~ 3
It resets all the latest three submissions, just as it has never been submitted.

Git reset version-B .txt

This damn line separator problem occurs on Windows platforms. It is generally recommended

Git config-global core. autocrlf false
You can also

Git config-global core. safecrlf true
Ensure that the line delimiters of files are not mixed. In case of git checkout or git reset-hard again

========================================================== ========================================================== ========================================================== ==========
View blob
Git show 6ff87c4664 view blob

View tree
Git ls-tree fb3a8bdd0ce view tree
Note: The mode bits of all files are 644 or 755, which means Git only cares about the executable bits of the files.

View A submission
Git show-s-pretty = raw 2be7fcb476

View tags
Git cat-file tag v1.5.0

Each directory creates a tree object (including the root directory), and each file creates a corresponding blob Object. finally, there is a commit object to point to the root tree object (root of trees), so that we can track each item submitted by the project.
A commit includes
One tree
Parent object (parent (s ))
Author
Submitted by committer

|-HEAD # The branch in which the git project is currently located
|-Config # configuration information of the project. The git config command will change it.
|-Description # Project description
|-Hooks/# default hook Script directory
|-Index # index file
|-Logs/# historical information of each refs
|-Objects/# all objects in the Git local repository (commits, trees, blobs, tags)
'-Refs/# identifies the commit (commit) that each branch of your project directs ).

. Git/refs/heads/master

. Git/refs/remotes/origin/master

// No commit is added.
Changes to be committed:
(Use "git reset HEAD ..." To unstage)

New file: yyy

// The original file is modified without adding
Changes not staged for commit:
(Use "git add ..." To update what will be committed)
(Use "git checkout -..." To discard changes in working directory)

Modified: test

// The new file has not been added
Untracked files:
(Use "git add ..." To include in what will be committed)

Xxx

Git config-global user. name "Scott Chacon"
Git config-global user. email "schacon@gmail.com"

Clone a repository
Git clone http://www.kernel.org/pub/scm/git/git.git [dir]

Initialize a new repository
Git init

In addition to the git add command, I can also use
$ Git commit-
This will automatically add all files whose content is modified (not including newly created files) to the index and submit them at the same time. Equivalent to add + commit

Git traces that the content is not a file
Git add is not only used to add new files not in version control, but also to add files that have been in version control but have just been modified;
In both cases, Git will get a snapshot of the current file and save the content to the index (stage) to prepare for the next commit.

For example:
After modifying test, git add and check
Changes to be committed:
Modified: mmm

Modify the test git status again.
Changes to be committed:
Modified: mmm

Changes not staged for commit:
Modified: mmm

Branch and merge @ Basics
View Current Branch
Git branch
Create
Git branch test
Switch to a branch
Git checkout branch
Merge
Git merge test

Git encourages extensive use of branches:

View branch: git branch

Create branch: git branch name

Switch branch: git checkout name

Create + switch branch: git checkout-B name

Merge a branch to the current branch: the operations after git merge name is merged the two branches will look the same

Delete branch: git branch-d name

The modified version is not added as version a, the added version is the index version, the commit version is the c version, and the pushed version is the r version.

Git diff
Find the difference between your current working directory and the last submitted Local index (Version a and Version c)
Git diff-cached
View the content to be submitted next time (staged, added to index) (index version and c version)

Git diff master .. test
Git diff master... Test than parent Branch

. Gitignore ignore files and do not prompt in Untracked files

Git stash stores the status at a certain time

Http://gitbook.liuhui998.com/3_6.html

Http://gitbook.liuhui998.com/4_9.html

Git Undo operation-reset, check out, And undo

============================= ========================================================== ======================================
Version rollback (before pushing ):

First, Git must know which version the current version is. In Git, use HEAD to indicate the current version, that is, the latest commit "3628164... 882e1e0 "(note that my submission ID is definitely different from yours). The previous version is HEAD ^, and the previous version is HEAD ^, of course it is easier to write 100 ^ in 100 versions, so it is written as HEAD ~ 100.

$ Git reset-hard HEAD ^
HEAD is now at ea34578 add distributed

The git log will be cleared.

Return to the latest git reflog to check the history and find the latest id.
Come back
$ Git reset-hard 3628164
HEAD is now at 3628164 append GPL

Run the git checkout-readme.txtidea command to undo all the modifications to the readme.txt file in the workspace. There are two situations:
Readme.txt has not been put into the temporary storage zone after modification. Now, undo the modification and return to the same status as the version database;
One is that readme.txt has been added to the temporary storage area and is modified again. Now, undo the modification and return to the status after it is added to the temporary storage area.
In short, this file is returned to the status of the last git commit or git add.

Undo modification:
Scenario 1: When you change the content of a file in the workspace and want to discard the modification, run the git checkout-file command.
Scenario 2: When you not only disrupt the content of a file in the workspace, but also add the file to the temporary storage area, you want to discard the modification in two steps. The first step is to use the command git reset HEAD file, return to scenario 1. Step 2: perform operations based on scenario 1.
Scenario 3: If you want to cancel the submission when you have submitted an inappropriate modification to the version library, refer to the version rollback section, provided that the submission is not pushed to the remote database.

Git checkout replaces the version of the workspace with the version in the version library. You can "Restore it with one click" Whether the workspace is modified or deleted ".

What is the difference between git rm-cache and git reset HEAD?

After git add <somefile>, sometimes you are prompted to use "git rm-cache" for unstage. Sometimes, you are prompted to use "git reset HEAD ".

To delete a file, you 'd better use git rm file_name instead of rm file_name directly in the workspace.
If a file has been added to the temporary storage area and there is no commit, there are two ways to do this:
1. Use the version library content to clear the staging area, git reset HEAD
2. Only delete a specific file from the temporary storage zone. git rm-cache file

> Sometimes you are prompted to use "git rm-cache" for unstage
Prompt when <somefile> is not found in HEAD

> Sometimes, "git reset HEAD" is prompted ".
<Somefile> prompt in HEAD

Add remote repo:
Git remote add upstream https://github.com/bkjia/first.git

To associate a remote library, run the command git remote add origin git @ server-name: path/repo-name.git;
After Association, use the command git push-u origin master to push all the content of the master branch for the first time;
After that, after each local commit, you can use the command git push origin master to push the latest modification as long as necessary;
One of the biggest advantages of a distributed version system is that you do not need to consider the existence of a remote database when working locally, that is, whether the remote database works normally or not, SVN refuses to work when there is no Internet connection! When there is a network, it is very convenient to push the local commit and synchronize it!

Git push
-U,-set-upstream

Https://github.com/bkjia/first.git

[Core]
Repositoryformatversion = 0
Filemode = true
Bare = false
Logallrefupdates = true
Ignorecase = true
Precomposeunicode = true
[Remote "upstream"]
Url = https://github.com/bkjia/first.git
Fetch = + refs/heads/*: refs/remotes/upstream /*

After you execute git push-set-upstream master

[Branch "master"]
Remote = upstream
Merge = refs/heads/master

Git remote add upstream https://github.com/bkjia/first.git
Git push-u upstream master
Or
Git push-set-upstream master

After
Branch master set up to track remote branch master from upstream.

View the cat. git/config file with more content
[Branch "master"]
Remote = upstream
Merge = refs/heads/master

[Root @ chenlong first] # git push-u upstream master
Username for 'https: // github.com ': zxsz
Password for 'https: // zxsz@github.com ':
Fatal: Authentication failed

Git config-global push. default simple/matching

The following describes the differences between push. default matching and push. default simple:

Push. default: git push pushes all your local branches to the remote host with the corresponding name. This means that you may inadvertently push some branches that you didn't intend to push.
Push. the default setting of simple means that git push only pushes the current branch to the corresponding branch from the original git pull. In addition, this process also checks whether the names of each branch correspond to each other.

[Root @ VM_44_174_CentOS first] # git push github master
Error: The requested URL returned error: 403 Forbidden while accessing https://github.com/bkjia/first.git/info/refs

Git remote set-url github https://github.com/bkjia/first.git

Ssh-keygen-t rsa-C "chenlongtest_txyun"

[Remote "origin"]
Fetch = + refs/heads/*: refs/remotes/origin /*
Url = https://github.com/bkjia/first.git

Url = git@github.com: bkjia/first. git.

Git log-graph-pretty = oneline

Https://www.kernel.org/pub/software/scm/git/

Centos Installation Error
Make [1]: *** Error 2
Yum install perl-ExtUtils-MakeMaker package
/Bin/sh: msgfmt: command not found
Yum install gettext-devel

Git branch-merged
Git branch-no-merged view jobs that have not been merged
Git branch-D test force Delete branch

Used when no commit is modified
Git stash storage current site
Git stash list

Git stash apply stash @ {0}
Git stash drop to delete
Equivalent
Git stash pop

When the work is not completed, first git stash the work site, then fix the bug, fix it, then git stash pop, and return to the work site.

Git merge-no-ff-m "merged bug fix 101" issue-101

Therefore, the working mode of multi-person collaboration is usually as follows:

First, you can try to use git to push origin branch-name to push your own changes;

If the push fails, you need to use git pull to try to merge the local updates because of the remote distribution ratio;

If a merge conflict exists, the conflict is resolved and submitted locally;

If there is no conflict or the conflict is resolved, you can use git push origin branch-name to push it!

If git pull prompts "no tracking information", the link between the local branch and the remote branch is not created. Run the git branch-set-upstream branch-name origin/branch-name command.

This is the working mode of multi-person collaboration. Once you are familiar with it, it is very simple.

Remote branch is recommended.
Git checkout-B branch-name origin/branch-name
Create an association between a local branch and a remote branch, and use git branch-set-upstream branch-name origin/branch-name

[Chenlong @ MD101 first] $ git checkout-B dev3 origin/dev3
Fatal: Cannot update paths and switch to branch 'dev3' at the same time.
Did you intend to checkout 'origin/dev3' which can not be resolved as commit?
[Chenlong @ MD101 first] $ git branch dev3
Git checkout dev3

Git push origin-delete

Git log-pretty = oneline-abbrev-commit

You can also create a label with a description. Use-a to specify the label name and-m to specify the description text:

$ Git tag-a v0.1-m "version 0.1 released" 3628164
Git tag-s v0.2-m "version 0.1 released" 3628164-s gpl Encryption

Git tag-d v0.1
Git push origin v1.0
Git push origin-tags push all

If the tag has been pushed to a remote device, it is troublesome to delete the remote tag. Delete the tag locally:

[Chenlong @ MD101 first] $ git tag-d v0.7
Deleted tag 'v0. 7' (was feb7a94)
Then, delete from the remote. The DELETE command is also push, but the format is as follows:

[Chenlong @ MD101 first] $ git push origin: refs/tags/v0.7 with spaces
To git@github.com: bkjia/first. git
-[Deleted] v0.7

Custom
Git config-global color. ui true
. Gitignore File

Git config-global alias. unstage 'reset head'
Git unstage test. py is equivalent
Git reset HEAD test. py

Git config-global alias. lg "log-color-graph-pretty = format: '% Cred % h % Creset-% C (yellow) % d % Creset % s % Cgreen (% cr) % C (bold blue) % Creset '-abbrev-commit"

Build a git Server

If you want the ssh public key to take effect, the. ssh directory permission must be 0700, And the. ssh/authorized_keys File Permission must be 0600.

Git: x: 1000: 1000:/home/git:/usr/bin/git-shell

Git clone git@203.195.207.137:/data/git_res/test. git

Ubuntu perfectly installs and builds a Git Server

GitHub Tutorials:

GitHub tutorials

Git tag management details

Git branch management

Git remote repository details

Git local Repository (Repository) Details

Git server setup and Client installation

Git Overview

Share practical GitHub tutorials

How to Build and use Git servers in Ubuntu

Git details: click here
Git: click here

This article permanently updates the link address:

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.