Notes version control-using Git

Source: Internet
Author: User
Tags commit file copy garbage collection zip using git version control system git clone git commands

Category: Git +2012-12 Notes version Control-using Git

I think everyone who learns git should have done something like this, because Git commands too much to look at and forget about the front, I've seen git before, but it's useless, and now I'm almost out of the picture, so this time I'm going to write down the commands I've seen to give myself a memo.

Git is already the most popular version control system, online related to a lot of free learning resources, I have seen the Chinese books are: Git Community book Chinese version Pro git Chinese version of git Magic Chinese version

But I bought it. A paper book called Version Control-using Git, below is all the commands I've written about almost the entire book: setting

git config-global user.name "nshen"//Must
git config-global user.email "nshen121@gmail.com"//Must
git config-global color.ui "always"//or "auto", always not only the base environment is color, DOS is also color.
git config-global core.editor notepad.exe//Set as Windows Notepad
git config-global alias.ci "commit"//alias abbreviation
git config-global merge.tool//You can set the merge tool
git config-global-list//view settings

In fact, these settings are all saved under C:\Documents and Settings\ user name \.gitconfig file (Windows)

View Help: Git helper command initialization:

Git init into version control:

git add *.txt//Add all TXT files
git add README//Add a single file
git Add. Add all files including subdirectories, but do not include empty directories

The add command is a multi-function command that, depending on the state of the target file, has a different effect: you can use it to start tracking new files, or to put tracked files into staging area, and to mark conflicting files as resolved when you merge, etc. note that each time you modify it, add it again. Otherwise, the previous add version will be submitted.

git add-i//Enter interactive add
Git add-p//directly into patch mode, you can temporarily save part of the changes. Submit:

git commit-m "initial project version"
Git commit-m "something" somefile//Submit specified file
git commit-c head-a-amend//multiplexing HEAD messages, supplemental submissions (minor bug changes without adding a commit record, masking your own sloppy) parameters:

-M "Instructions for submission"
-A moves all the files that have been tracked and submits them. (Files that have been modified in the working directory are submitted to the repository without a manual add)
-amend Supplementary Submissions
-C re-use the submitted message of the specified submission
-C Open Editor to edit changes based on existing submissions

E.g modify the last commit:

git commit-m ' initial commit ' git add forgotten_file git commit--amend

If no modifications are equivalent to the change submission instructions, the top 3 commands get a commit. ignore the submitted file:

All the files that everyone needs to ignore are written in the. gitignore file, and only the files that your personal preferences need to ignore are written in the. git/info/exclude file

Grammar:

# This is a comment – will be ignored by Git *.a       # ignores all. A end of file!lib.a    # but LIB.A except *.[ OA]  #忽略以. O or. A files ending with *~      #忽略以 ~ end of File/todo     # simply ignore the TODO file under the project root, not including Subdir/todo build/    # Ignore All files in build/directory Doc/*.txt # ignores Doc/notes.txt but does not include Doc/server/arch.txt
To view file changes:

git diff//Compare the difference between working directory and cache
The difference between git diff-cached or git diff-staged//cache and Repository
git diff HEAD//The difference between the three

Note that git diff alone only shows changes that haven't been staged yet, not the difference between this work and the last commit. So sometimes when you save all the updated files, you run Git diff and nothing, that's why.
git diff 18f822e//18f822e This version differs from the current directory

Git diff aaaaa. BBBBB//Compare differences between AAAAA and BBBBB
Git diff-stat can statistic data, compare special commands to rename , move, delete files:

git mv file_from file_to//renaming or moving

$ git mv README.txt README $ git status # on branch Master # Your branch was ahead of ' Origin/master ' by 1 commit. # # Changes to being committed: # (use "git reset HEAD <file> ...." To Unstage) # # renamed:    README.txt, README

In fact, running git MV is equivalent to running the following three commands:

$ mv README.txt README
$ git rm README.txt
$ git Add README

The git RM file name must be called//removed from staging area and the file is also deleted

If you delete the file manually, the Git status will appear when you run

# Changed But isn't updated: # (use "Git add/rm <file> ..." To update what'll be committed) # # deleted:    Grit.gem Spec

The git RM file name must be run at this point before it is no longer included in version management at the time of submission.
If the deletion has been modified before and has been add to the buffer, you must forcibly remove the-f

Another scenario is that we want to remove the file from the Git repository (that is, remove it from the staging area), but still want to keep it in the current working directory. In other words, it is only removed from the tracking list. For example, some large log files or a bunch of. A compile files, accidentally into the warehouse, to remove the trace but not delete the file, so that later in the. gitignore file, with the-cached option: View status: View the current status :

git status

$ git status # on branch Master # changes to be committed:  //As long as this line is behind, the description is put into the staging area # (use "git reset HEAD <file> ...") to Unstage)//Want to de-cache git reset HEAD README # # New file:   Readme # Changed  but not updated://trace file content changed, but still not put to staging area, Need git add command to put into staging area # (use "git add <file> ...." To update the "what'll be Committed) # (with" Git checkout--<file> ;... "To discard changes in working directory)//delete modify, revert to previous version, be at risk (if you want to keep and fallback version is handled with stashing and branches) # Modified:   Benchmark S.rb
View commit history:

git log

Then "J" Down, "K" to browse, "Q" exit

git log-pretty=oneline//Line display
-pretty= "%h%s"//output in various formats

Git log–p-2//-p Show content differences per Commit-2 represents the last 2 changes

Git log-since "5 hours"
-since "3 Hours"
-since "1 Minute"
-before = "2008-10.01"

git log 27j34j3j. 03u43u23//Oldest version: Latest version (excluding start point only)
git log 34j4j4. HEAD
git log fhfs8fh. Omit head
git log "head^^" ... " head^ "//windows must be quoted for backtracking on previous commit
git log-1 head~1//equivalent to Git log-1 head^

git log-graph//graphical display of branches
git log-graph-pretty=oneline//Line graphical Display Branch accountability : Find out who changed the code

git blame hello.html//You can also specify the start and end lines in the command (blame) with the "-L" parameter:
git blame-l 12,+10 hello.html//12 to 22 rows
Blame can also track content replication, file copy, and see version Control 79 page revocation: undo Buffer Changes (no commit)

Git checkout head file name//Undo Staging Area Modification
git checkout head readme.txt Todo.txt
git checkout head *.txt
Git checkout head. Undo all Reversal commits:

git revert HEAD//create a reverse new commit to counteract the original commit change
If you need to invert multiple, you must reverse from the last start, plus-n can not be submitted immediately, and then submitted together.
Git revert-n HEAD
Git revert-n 54efhds
git commit-m "revert head and 54efhds" Reset: There is no commit to get the working directory back to the last commit state

git reset-hard HEAD//Empty all uncommitted content, which makes the "Git diff" and "Git diff-cached" commands appear empty
git reset-soft HEAD//Reset repository, staging differences to make it useful to find errors when they need to be changed (e.g., private passwords inside) branch: branches at the tip of the current branch:

Git branch rb_1.0 (the branch does not automatically switch over) to switch branches:

git checkout rb_1.0 (switch to rb_1.0 Branch) to Create and switch branches:

Git checkout-b rb_1.0 (simplifies top 2 steps) Delete branch:

Git branch-d rb_1.0 creates a new branch based on a commit, branch, or tag:

Git branch rb_1.0 Master
Git branch rb_1.0 6fe57de0
Git Branch rb_1.01 1.0 View Branch:

GIT branch//list local branch  iss53 * Master  //* indicates the current branch  testing

Git branch-r//Display remote Branch
Git branch-a//Lists all branch branches renamed:

git branch-m master MyMaster
-M capital M overrides a branch merge branch with the same name:

Direct Merge:
Git merge the source branch name that you want to merge into the current branch
git merge-no-commit branch//merge but do not commit

Press-Fit Merge: The branch is pressed into a commit record and merged.
git Merge-squash a bug branch
Git commit-m "fix a Bug"

Picking Merge: Merge only one commit
Git Cherry-pick 321d76f
If sequential picking is required, you need to add the-n parameter
Then git commit, but do not add the-m parameter, the editor will use the newly-chosen submission message as the current message. tag tag: View Tags:

git tag to create tags:

Git tag 1.0//Last Commit on current branch create tag
Git tag 1.0 rb_1.0//New kicks based on rb_1.0 branch Create tags
Git tag 1.0 ae468d8kt//Create a label check- out label for a commit:

Git checkout 1.0//Check out tag is the same as checking out a branch, but checking out the label and using Git branch to view the local branch will find you are no longer on any branch
You should not modify it at this point, but you should create a branch immediately based on this tag
Git checkout-b from-1.0 :

1) Git rebase rb_1.01//may have modified a bug and want the new version to be base on the rb_1.01 branch
2) Resolve conflicts manually//If you cannot resolve direct git rebase-skip or-abort to skip a specific commit or completely discard a variable base
3) git add xxx.html//conflict Resolution
4) Git rebase-continue

The-onto parameter can rewrite the history erase the intermediate parameters, the first parameter to the penultimate argument to the 3rd parameter, in order to prevent errors suggested on the experimental branch first Test.

Rebase-i can sort history, multiple commits are merged into 1, one commit is decomposed into multiple commits,
See version control p86, need editor support, Windows Notepad not remotely Related:

git clone git://github.com/schacon/grit.git//clone from an existing repository
git clone git://github.com/schacon/grit.git mygrit//name change, the only difference is that the newly created directory is Mygrit, and the others are added as remote repositories:

Git remote add PB git://github.com/paulboone/ticgit.git
Clone will add the origin repository by default, and if it was originally created with Git init and later wanted to commit to the remote repository, you can use the method below
Git remote add Origin git@example.com:/xxxxxx to view the Remoting branch:

git remote-v//view remote repository, after default clone, there should be a origin repository,-V to display the corresponding clone address
git remote show origin//view remote Repository information repository rename and delete:

Git remote rename PB paul
Git remote RM Paul Gets the data:

git fetch [remote-name] pulls remote repository to local remote repository, does not automatically merge    //$ Git fetch origin $ git fetch PB remote:counting objects:58, done. Re Mote:compressing objects:100% (41/41), done. Remote:total (Delta), reused 1 (Delta 0) unpacking objects:100% (44/44), done. From Git://github.com/paulboone/ticgit * [New branch]      master,     pb/master * [New branch]      ticgit     - > Pb/ticgit

Now pb/master can be accessed locally, you can merge into one of your own branches, or switch to this branch to see what interesting updates

Git pull fetch data is merged into the current branch push data in the working directory:

git push [remote-name] [branch-name]//default to Git push Origin master

Git push Origin serverfix//Push branch is actually a simplification of the sentence below, extracting my serverfix and updating it to the remote repository Serverfix

Git push Origin Serverfix:serferfix

git push origin:serverfix//This syntax is used to delete, just leave the semicolon before leaving the other:

Git GC//garbage collection, which runs once every once in a while for example one months, reduces disk space consumption.
Git reflog//Last safeguard, list the things that were mistakenly deleted
git bisect//Two-point lookup, version control p124 page, slightly archive Repository, export compression package:

git archive-format= format-prefix= directory/version > compressed package. zip
Git archive-format=zip head>

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.