标签:
git是常用的版本控制工具,对于git你需要了解它的几个重要的概念——工作区,版本库,暂存区,master
工作区有一个隐藏目录.git,这个不算工作区,而是Git的版本库。
暂存区
就是称为stage(或者叫index)的。
master
master是Git为我们自动创建的第一个分支,以及指向master的一个指针叫HEAD。
我们通常在工作区进行增删改内容后,需要通过git add命令,把文件添加到暂存区中,通过git commit命令把文件提交到master中。这样git就会保存你的记录。
git常用的几个命令
git init
-初始化git,在文件夹中生成.git的隐藏文件夹
git add 文件名/option(参数)
--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 that the path will 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 are ignored in dry run
-q, --quiet suppress summary after successful commit
-v, --verbose show diff in commit message template
Commit message options
-F, --file <file> read message from file
--author <author> override author for commit
--date <date> override date for commit
-m, --message <message>
commit message
-c, --reedit-message <commit>
reuse and edit message from specified commit
-C, --reuse-message <commit>
reuse message from specified commit
--fixup <commit> use autosquash formatted message to fixup specified commit
--squash <commit> use autosquash formatted message to squash specified commit
--reset-author the commit is authored by me now (used with -C/-c/--amend)
-s, --signoff add Signed-off-by:
-t, --template <file>
use specified template file
-e, --edit force edit of commit
--cleanup <default> how to strip spaces and #comments from message
--status include status in commit message template
-S, --gpg-sign[=<key-id>]
GPG sign commit
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 be 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)
On branch master
nothing to commit, working directory clean
如果是add后,会显示
warning: CRLF will be replaced by LF in 1.txt.
The file will have its original line endings in your working directory.
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: 1.txt(这是我测试的文件)
$ git log
commit d82fce6bc6a140ca09390918de6afb40642f1133
Author: xxx(这里显示的是你git账号信息)
Date: Sun Mar 27 11:00:13 2016 +0800
#(提交信息)
commit 7d525203a7e81171596e3c5802150a5190121566
Author: xxx
Date: Sun Mar 27 10:41:05 2016 +0800
111(提交信息)
$ git reflog
d82fce6 HEAD@{0}: commit: #
7d52520 HEAD@{1}: commit (initial): 111
d82fce6 –类是于每次提交的id,可以通过id恢复到对应的版本,也就是
commit d82fce6bc6a140ca09390918de6afb40642f1133的前7位。
$ git reset --hard d82fce6
HEAD is now at d82fce6 #
$ git reset --hard HEAD^
HEAD is now at 7d52520 111
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Forward-port local commits to the updated upstream head
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
‘git help -a‘ and ‘git help -g‘ list available subcommands and some
concept guides. See ‘git help <command>‘ or ‘git help <concept>‘
to read about a specific subcommand or concept.
git生成ssh证书
如果一切顺利的话,可以在用户主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人。
使用github托管代码
github将在git上生成的ssh的公约内容,在github上认证
如图
github创建repository
git remote add origin git@github.com:github用户名/xxx.git(非常重要)
这是将git代码托管到github.com网站上的命令,指定托管的位置。
或者使用
git remote add origin https://github.com/github用户名/xxx.git
二者的协议不同,前者是ssh协议,或者是https协议。
git push -u origin master
文章参考:
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
标签:
原文地址:http://blog.csdn.net/qq_33689414/article/details/50991005