Git is a popular version control tool, and for git you need to understand several important concepts--workspaces, repositories, staging area, master
- Work area
-Workspaces refer to the directories you see on your computer (. Git folder is Git's repository, which is generated when git initializes), such as:
- Version Library
The workspace has a hidden directory. Git, this isn't a workspace, it's a git repository.
Staging Area
is called the stage (or index).
Master
Master is the first branch that git automatically creates for us, and a pointer to master called head.
We usually use the git add command to add files to the staging area and commit the files to master via the git commit command after we have made the additions to the workspace. Then Git will save your records.
Several common commands for git
--N,--dry-run Dry run-V,--verbose be verbose-I,--interactive Interactive picking-p,--patch select hunks interactively-e,--edit Edit current diff and apply-F,--force allow adding otherwise ignored files-u,--update update tracked files- N,--intent-to-add record only the fact , the path would be added later- A,--all add changes from all tracked and untracked files--ignore-removal Ignore paths removed in the working tree (same as--no-all)--refresh Don' t add, only refresh the index --ignore-errors just skip files which cannot be added because of errors--ignore-missing Check if -even missing-files is ignored in dry run
- git commit option (parameter, add according to the actual situation)-M "submitted descriptive information" or-M ' # '
- ' # ' means no information is submitted or the submission is ignored.
-M does not write will not let you commit, the submission fails.
The option parameters are:
-q, --quiet suppress summary after successful commit-v, --verbose show diff in commit message template
CommitMessage options-f,--file <file>ReadMessage fromFile--author <author> override author for Commit--Date<Date> OverrideDate for Commit-M,--message <message>CommitMessage-c,--reedit-message <Commit> Reuse andEdit Message fromSpecifiedCommit-C,--reuse-message <Commit> Reuse Message fromSpecifiedCommit--fixup <Commit> Use Autosquash Formatted message toFixup specifiedCommit--squash <Commit> Use Autosquash Formatted message toSquash specifiedCommit--reset-author theCommit isAuthored byMe Now (used with-c/-c/--amend)-S,--signoffAddsigned-off- by:-T,--template <file> use specified template file-e,--edit Force edit of Commit--cleanup <default> How toStrip spaces and#comments fromMessage--status include statusinch CommitMessage Template-s,--gpg-sign[=<Key-id>] GPG signCommit
Commit Contents Options-A,--all commit all changed files-I,--include add specified files to index for commit--interactive interactively Add files-p,--patch interactively add changes-O,--only commit only specified files-N,--no-verify bypass pre-commit Hook--dry-run Show what would is committed--short Show Status concisely--branch Show Branch information--porcelain machine-readable output--long Show Status in long format (default)-Z,--null terminate entries with NUL --amend Amend previous commit--no-post-rewrite bypass Post-rewrite Hook-u,--untracked-files[=<mode>]Show untracked files, optional modes:all, Normal, No. (Default:all)
- git status
- Used to view the status of git, which is typically displayed after a commit
On branch masternothingto commit, working directory clean
If it is add, it will show
CRLFbyin1.filelineindirectoryto be committed: "git reset HEAD <file>..."to unstage) modified: 1.txt(这是我测试的文件)
- git log
- Used to view the submitted information
$ git logcommit d82fce6bc6a140ca09390918de6afb40642f1133author: xxx (shown here is your git account information) date: Sun Mar 27 11 : 00 : 13 2016 +0800 # (Submit message) commit 7 D525203a7e81171596e3c5802150a5190121566author: xxxDate : Sun Mar 27 10 : 41 : 05 2016 +< Span class= "Hljs-number" >0800 111 (Commit information)
- Git reflog
- is also used to view the submission information
$ git reflogd82fce6 HEAD@{0}#7d52520 HEAD@{1}111
The d82fce6– class is the ID of each commit and can be restored to the corresponding version by ID, i.e.
The first 7 bits of commit d82fce6bc6a140ca09390918de6afb40642f1133.
- git reset
- Return to previous version – Specify a version (via ID)
- Git Reset–hard d82fce6 (return to the specified version)
- $ git reset–hard head^ (back to previous version, ^ There are several to return to previous versions)
--hard d82fce6isat#
--hard HEAD^isat7111
- Git–help
- These is common Git commands used in various situations:
a working area (see also: git help tutorial) clone aintoanewdirectory init anemptyoranone
WorkOn the also: git Help Everyday) AddAddfileContents to theIndex MV Moveor Rename a file,a Directory,or aSymlink Reset Reset Current HEAD to theSpecified state RM RemoveFiles from theWorking tree and from theIndex
theand state (see also: git help revisions) bisect tothea bug grep linesa pattern log Show commit logs show of objects status the working tree status
Grow, Mark. andTweak your common history branch List,Create,or DeleteBranches checkout Switch BranchesorRestore Working treeFilesCommit Record Changes to theRepository diff Show changes between commits, commit andWorking tree, etcMergeJoin Both orMore development histories together rebase Forward-portLocalCommits to theUpdated upstream head tag Create, list,Delete orVerifyaTag Object signed withGpg
collaborate (see also: git help workflows) fetch andfrom another repository pull fromandwithoralocal branch push with associated objects
‘git help -a‘and‘git help -g‘and‘git help <command>‘or‘git help <concept>‘toreadaor concept.
- Cat file name (including extension)
View the contents of a single file
git generates an SSH certificate
- $ ssh-keygen-t rsa-c "[Email protected]"
- You need to change your email address to your own e-mail address, then return
You need to change the email address to your own email address, and then return to the default value, as this key is not used for military purposes, so there is no need to set a password.
If all goes well, you can find the. SSH directory in the user's home directory, there are Id_rsa and id_rsa.pub two files, these two are SSH key key pair, Id_rsa is the private key, can not be leaked out, Id_rsa.pub is the public key, can be assured to tell anyone.
Using GitHub managed code
GitHub Create repository
git remote add origin [email protected]:github user name/xxx.git (very important)
This is the command to host git code on the github.com Web site, specifying the managed location.
or use
Git remote add Origin https://github.com/github user name/xxx.git
The protocol is different, the former is the SSH protocol, or the HTTPS protocol.
Git push-u Origin Master
- Uploading Files to github.com
--but in the push will be error, I did not solve, more than a few times good. ——
Article reference:
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
git introduction and upload code to GitHub