标签:div ola color 提示 cond 也有 button 微软 tle
然后,在工作区,也就是learngit 目录下,新增一个LICENSE文本文件(内容随便写)。我们拷贝一段apache的:
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION好。这个时候,我们使用一下git status这个命令,来查看下:
$ git status On branch master 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: README.md Untracked files: (use "git add <file>..." to include in what will be committed) LICENSE no changes added to commit (use "git add" and/or "git commit -a")
tonyyang@021ZJ1315 /d/learngit (master) $ git add README.md tonyyang@021ZJ1315 /d/learngit (master) $ git add LICENSEok,之前说过没有任何输出代表成功了。现在就是将工作区(working Directory)的代码提交到了暂存区(stage),所以这一步的操作,我们画图就是这样:
tonyyang@021ZJ1315 /d/learngit (master) $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: LICENSE modified: README.md它提示我们2个文件,一个是new新的,一个modified修改过,都已经提交到暂缓区,但是都没提交commit到master分支。也就是说现在暂存区是有东西的。
$ git commit -m "modify README.md and add a new LICENSE file" [master b4a73ed] modify README.md and add a new LICENSE file 2 files changed, 6 insertions(+) create mode 100644 LICENSEok,commit成功了。提示我们成功了。那么,现在的暂存区状态是什么样子呢?我们也来画图看看:
$ git status On branch master nothing to commit, working directory clean它提示我们都已经提交了,工作区也是干净的。
$ vi README.md Git is a distributed version control system. Git is free software. it is a good tool. distributed under the GPL. Git has a mutable index called stage. Git tracks changes.
$ git add README.md $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: README.md提示我们已经添加到了暂存区。
$ vi README.md Git is a distributed version control system. Git is free software. it is a good tool. distributed under the GPL. Git has a mutable index called stage. Git tracks changes of files.
$ git commit -m "git tracks changes" [master a2f0cbc] git tracks changes 1 file changed, 1 insertion(+)ok,提示我们已经commit成功,我们现在再用git status这个命令查看下状态
$ git status
On branch master
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: README.md
no changes added to commit (use "git add" and/or "git commit -a")
我们发现,第三步我们的修改 Git tracks changes of files. 还存放在工作区,没有被commit。为毛会这样呢?别激动,我们一开始不就说了嘛:git 跟踪管理的是你的每一次修改,并不是这个文件。$ git diff diff --git a/README.md b/README.md index f4febdd..0262b58 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ Git is a distributed version control system. Git is free software. it is a good tool. distributed under the GPL. Git has a mutable index called stage. -Git tracks changes. +Git tracks changes of files.可见,第二次修改确实没有被提交。
那怎么提交第二次修改呢?你可以继续add再commit,也可以别着急提交第一次就commit修改,先add第二次修改,再commit,就相当于把两次修改合并后一块提交了:
第一次修改 -> add -> 第二次修改 -> add -> commit
Git is a distributed version control system. Git is free software. it is a good tool. distributed under the GPL. Git has a mutable index called stage. Git tracks changes of files. xiaowang is sb.现在想想不应该骂他的,反悔了。那我如何撤销我刚才的修改呢?你说我一行行的手动去掉行不行?当然可以。但是这样做就真的是sb了。要是工作量太大,那不还把人搞死啊。
$ git status On branch master 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: README.md no changes added to commit (use "git add" and/or "git commit -a")正是说明了我刚才加的还在工作区,还没add到暂存区。它也提示我们 use "git checkout -- <file>..." to discard changes in working directory
$ git checkout -- readme.txt
我们试一下:$ git checkout -- README.md $ git status On branch master nothing to commit, working directory clean
$ vi README.md Git is a distributed version control system. Git is free software. it is a good tool. distributed under the GPL. Git has a mutable index called stage. Git tracks changes.OK,恢复到修改之前了。
$ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: README.md提示我们已经加到暂存区了,准备提交。
$ git reset HEAD README.md Unstaged changes after reset: M README.mdok,提示我们撤销unstage成功。我们再看下status
$ git status On branch master 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: README.md no changes added to commit (use "git add" and/or "git commit -a")非常完美,已经撤销到工作区了。那你如果也想工作区里的也撤销咋搞。那就是前面的第一种情况了,一步步的来:
$ git checkout -- README.md $ git status On branch master nothing to commit, working directory clean
$ vi README.md Git is a distributed version control system. Git is free software. it is a good tool. distributed under the GPL. Git has a mutable index called stage. Git tracks changes.
$ git reflog 29e9c55 HEAD@{1}: commit: xiaowang is sb a2f0cbc HEAD@{2}: commit: git tracks changes b4a73ed HEAD@{3}: commit: modify README.md and add a new LICENSE file c790395 HEAD@{4}: reset: moving to c790395 0e87e34 HEAD@{5}: reset: moving to HEAD^ c790395 HEAD@{6}: reset: moving to c790395 0e87e34 HEAD@{7}: reset: moving to HEAD^ c790395 HEAD@{8}: commit: add GPL 0e87e34 HEAD@{9}: commit: it is a good tool 4b86146 HEAD@{10}: commit: modify a line c96a8e5 HEAD@{11}: commit (initial): write a new readme.md file $ git reset --hard a2f0cbc HEAD is now at a2f0cbc git tracks changesok。恢复了。
$ vi test.txt this file is will delete
$ git add test.txt $ git commit -m "test.txt" [master 4b8661a] test.txt 1 file changed, 1 insertion(+) create mode 100644 test.txt然后,我们手动将其删除:
$ rm test.txt $ git status On branch master Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) deleted: test.txt no changes added to commit (use "git add" and/or "git commit -a")我们已经捕捉到text.txt被删除了。如果我们是确认删除,我们可以用git rm file这个命令删掉,并且git commit -m "msg"提交确认。如果你没有用git rm 命令,直接commit会提示,而且会提交不成功。
$ git rm test.txt rm ‘test.txt‘ $ git commit -m "delete test" [master f6a084e] delete test 1 file changed, 1 deletion(-) delete mode 100644 test.txt好。ok就删除掉了。
$ git checkout -- test.txt
$ git reset --hard HEAD^好了。搞定。
4 .修改:当你不但改乱了工作区某个文件的内容,还添加到了暂存区时,想丢弃修改,分两步,第一步用命令git reset HEAD file,在用git checkout -- file
5. 修改:已经提交了不合适的修改到版本库时,想要撤销本次提交,要用 git reset -- hard commit_id 来版本回退
6. git rm用于你确认删除一个文件
标签:div ola color 提示 cond 也有 button 微软 tle
原文地址:https://www.cnblogs.com/zst062102/p/12772162.html