git使用
http://www.cnblogs.com/newP/archive/2016/08/03/5732431.html
git show
git show c5f5
用git show <commit-hashId> 便可以显示某次提交的修改内容
同样 git show <commit-hashId> filename 可以显示某次提交的某个内容的修改信息。
git diff
git log 查看提交日志
git branch
git
git status
1) 所有还没有被git管理的文件(Untracked files)
3) Changes to be committed 的文件
示例:
git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: RouteConfig.cs
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: WebApiConfig.cs
modified: ../QcApi.csproj
modified: ../QcApi.csproj.user
modified: ../Scripts/_references.js
modified: ../Startup.cs
modified: ../Web.config
modified: ../packages.config
Untracked files:
(use "git add <file>..." to include in what will be committed)
../../.vs/
../../ConsoleSample/
../APILog/2017-03-03-api.log
../APILog/2017-03-17-api.log
../APILog/2017-03-20-api.log
../Areas/RouteDebugger/
../Content/bootstrap-responsive.css
../Content/bootstrap-responsive.min.css
../obj/
../../packages/
git add
git reset 或 git rm --cached <added_file_to_undo>
撤销git add 使用 Git rm 命令即可,有两种选择,
一种是 git rm --cached "文件路径",不删除物理文件,仅将该文件从缓存中删除;
一种是 git rm --f "文件路径",不仅将该文件从缓存中删除,还会将物理文件删除(不会回收到垃圾桶)。
dos 下 结果过滤,find, 例如: git status | find /i "release"
计算结果总行数 git status | find /c /v ""
/c 表示计算行数 /v "" 表示非空行 /i 表示忽略大小写
git commit -m "备注"
git commit -am "备注" //提交全部更改
git push origin master
git pull origin master --allow-unrelated-histories
放弃本地修改,直接覆盖之
git reset --hard
git pull
远程操作的第一步,通常是从远程主机克隆一个版本库,这时就要用到git clone命令。
$ git clone <版本库的网址>
比如,克隆jQuery的版本库。
$ git clone https://github.com/jquery/jquery.git
http://git.oschina.net/rocky132
git配置
简易的命令行入门教程:
Git 全局设置:
git config --global user.name "rocky132"
git config --global user.email "rockywood@163.com"
创建 git 仓库:
mkdir runrunbox_site_2016
cd runrunbox_site_2016
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://git.oschina.net/rocky132/runrunbox_site_2016.git
git push -u origin master
已有项目?
cd existing_git_repo
git remote add origin https://git.oschina.net/rocky132/runrunbox_site_2016.git
git push -u origin master
查看更改对比
如果我们想比较一个文件在工作区与暂存区的更改状态,我们可以使用 git diff
命令。
Administrator@LS1412PC0008 MINGW64 /d/work/test (master)
$ git diff name.txt
diff --git a/name.txt b/name.txt
index 465f661..d48e0e5 100644
--- a/name.txt
+++ b/name.txt
@@ -1,3 +1,4 @@
my name is shentao - 12345
new add line
new add line 2
+new add line 3
如果想查看该文件在暂存区与分支中的更改对比,可以通过附加 --cached
实现
Administrator@LS1412PC0008 MINGW64 /d/work/test (master)
$ git diff --cached
diff --git a/name.txt b/name.txt
index 8535cbf..465f661 100644
--- a/name.txt
+++ b/name.txt
@@ -1,2 +1,3 @@
my name is shentao - 12345
new add line
+new add line 2
若是想直接查看工作区与分支的对比状态,则可以附加 HEAD
参数。
Administrator@LS1412PC0008 MINGW64 /d/work/test (master)
$ git diff HEAD
diff --git a/name.txt b/name.txt
index 8535cbf..d48e0e5 100644
--- a/name.txt
+++ b/name.txt
@@ -1,2 +1,4 @@
my name is shentao - 12345
new add line
+new add line 2
+new add line 3
回滚文件
git checkout name.txt 从暂存区回滚工作区文件
git checkout head name.txt 从分支回滚工作区文件及暂存区文件
git reset name.txt 撤消上一次提交到暂存区的文件的更改
git reset name.txt
Unstaged changes after reset:
M name.txt