- download address:
- https://git-scm.com/download/
2.open Git Bash and input 'git' you will see all operation:
$ git
usage: git [--version] [--help] [-C ] [-c name=value]
[--exec-path[=]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=] [--work-tree=] [--namespace=]
[]
These are common Git commands used in various situations:
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 Reapply commits on top of another base tip
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 ' or 'git help '
to read about a specific subcommand or concept.
- initalized a repository use 'git init'
$ git init
Initialized empty Git repository in E:/xiaocai/code/git_test/.git/
4.create some directory and file , then see the status using 'git status'
mkdir test ==> cd test ==> touch a.md ==> vim a.md ==> input some word
---
$ git status
On branch master
No commits yet
Untracked files:
(use "git add ..." to include in what will be committed)
test/
nothing added to commit but untracked files present (use "git add" to track)
it show some change hasnot commit yet
5.using 'git add' to add the change
$ git status
On branch master
No commits yet
Untracked files:
(use "git add ..." to include in what will be committed)
test/
nothing added to commit but untracked files present (use "git add" to track)
CaiRR@YuHeng-PC MINGW64 /e/xiaocai/code/git_test (master)
$ git add test
6.commit the change with "git commit -m 'some message' "
$ git commit -m 'first conmmit'
[master (root-commit) 919a865] first conmmit
Committer: unknown
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:
git config --global --edit
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 1 insertion(+)
create mode 100644 test/a.md
CaiRR@YuHeng-PC MINGW64 /e/xiaocai/code/git_test (master)
$ git status
On branch master
nothing to commit, working tree clean
the difference between 'add' and 'commit':
- ' add ' : just like put it into a temporary space
- ' commit ' : is put it into repository
7.check the history with 'git log'
$ git log
commit 919a865770adfd83dc4771829c31248b8a583929 (HEAD -> master)
Author: unknown
Date: Wed Aug 16 10:39:00 2017 +0800
first conmmit
8.create a branch with 'git branch xx' or see the branch 'git branch'
$ git branch
* master
CaiRR@YuHeng-PC MINGW64 /e/xiaocai/code/git_test (master)
$ git branch x
CaiRR@YuHeng-PC MINGW64 /e/xiaocai/code/git_test (master)
$ git branch
* master
x
start with ' * ' mean current using
9.change the branch with 'git checkout x'
CaiRR@YuHeng-PC MINGW64 /e/xiaocai/code/git_test (master)
$ git checkout x
Switched to branch 'x'
CaiRR@YuHeng-PC MINGW64 /e/xiaocai/code/git_test (x)
$ git branch
master
* x
10.in new branch create some file and commit the merge to 'master' branch
1.create some file and commit
:touch x.md ==> vim x.md ==> input some word and save ==> git add x.md ==> git commit -m 'some message'
2.change the branch
$ git checkout master
Switched to branch 'master'
3.merge the branch
$ git merge x
Updating 919a865..0deb1f1
Fast-forward
x.md | 1 +
1 file changed, 1 insertion(+)
create mode 100644 x.md
- delete the unuse branch
$ git branch -d x
Deleted branch x (was 0deb1f1).
CaiRR@YuHeng-PC MINGW64 /e/xiaocai/code/git_test (master)
$ git branch
* master
if you want to delete it force (as no merge to master), using 'git branch -D x'
12.using tag to make a mark,we can change between different tag
1.create tag:
$ git tag -a v1.0.0 -m 'version 1.0.0'
2.make same change after that tag and create new tag
touch tag.md ==> vim tag.md ==> git add tag.md ==> git commit -m 'some msg'
$ git commit -m 'commit after v1.0.0'
3.checkout back to before tag
$ git checkout v1.0.0
learn more: https://git-scm.com/book/zh/v1/%E8%B5%B7%E6%AD%A5