First, create a git repository
1. Under the address where you need to create the repository, right click on git bash here
$ mkdir learngit
$ cd learngit
$ pwd
/Users/michael/learngit
mkdir+文件名 创建版本库名称
cd+ file name into repository
$ git init
Initialized empty Git repository in /Users/michael/learngit/.git/
An empty warehouse was created and appears under the current directory. Git
Ii. Commit Changes to Repository
After changing, adding, deleting files in the warehouse, enter (assuming the file name is "readme.txt"):
$ git add readme.txt
$ git commit -m "wrote a readme file"
[master (root-commit) cb926e7] wrote a readme file
1 file changed, 2 insertions(+)
create mode 100644 readme.txt
This will commit the changes to the repository.
Iii. Common Commands
git statuscommand allows us to always grasp the current state of the warehouse;
git diffAs the name implies is to view the difference, to see where changes have occurred;
cat+ file name to view the contents of the files
git log可以查看提交历史,以便确定要回退到哪个版本
git log --pretty=oneline 输出日志,以一行显示
$ git log --pretty=oneline3628164fb26d48395383f8f31179f24e0882e1e0 append GPLea34578d5496d7dd233c827ed32a8cd576c5ee85 add distributedcb926e7ea50ad11b8f9e909c05226233bf755030 wrote a readme file
3628164fb26d48395383f8f31179f24e0882e1e0是commit id版本号
git reset --hard 3628164 3628164是commit id版本号的一部分
git reset --hard HEAD^在Git中,用HEAD表示当前版本,上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。
git reflog查看命令历史,以便确定要回到未来的哪个版本
git add--all commits all changes
git push Origin master pushes the repository into the online repository
From
Http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/ 001375233990231ac8cf32ef1b24887a5209f83e01cb94b000
Common git operations