其他分享
首页 > 其他分享> > git反悔

git反悔

作者:互联网

Checkout

checkout命令用于从历史提交(或者暂存区域)中拷贝文件到工作目录,也可用于切换分支。 ![](./_image/2016-07-14 21-26-37.jpg?r=49) ![](./_image/2016-07-14 21-15-47.jpg?r=49&f=2) 匿名分支:如果既没有指定文件名,也没有指定分支名,而是一个标签、远程分支、SHA-1值或者是像 master~3 类似的东西,就得到一个匿名分支,称作 detached HEAD(被分离的 HEAD 标识)。

![](./_image/2016-07-14 21-44-06.jpg?r=56)

当HEAD处于分离状态(不依附于任一分支)时,提交操作可以正常进行,但是不会更新任何已命名的分支。(你可以认为这是在更新一个匿名分支。)一旦此后你切换到别的分支,比如说 master,那么这个提交节点(可能)再也不会被引用到,然后就会被丢弃掉了。注意这个命令之后就不会有东西引用 2eecb。详细查看:visual-git-guide#detached 但是,如果你想保存这个状态,可以用命令 git checkout -b name 来创建一个新的分支。 ![](./_image/2016-07-14 21-45-50.jpg?r=56)

Log

Description : Shows the commit logs. The command takes options applicable to the git rev-list command to control what is shown and how, and options applicable to the git diff-* commands to control how the changes each commit introduces are shown. git log [options] [revision range] [path]

常用命令整理如下:

log 的目的就是为了查看改动点来排查问题,除了 git log 还可以使用 git show 、git blame 来查看文件的改动。

Undo things

git filter-branch --env-filter ' OLD_EMAIL="your-old-email@example.com" CORRECT_NAME="Your Correct Name" CORRECT_EMAIL="your-correct-email@example.com" if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] then export GIT_COMMITTER_NAME="$CORRECT_NAME" export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" fi if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] then export GIT_AUTHOR_NAME="$CORRECT_NAME" export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" fi ' --tag-name-filter cat -- --branches --tags ``` 

Reset

reset命令把当前分支指向另一个位置,并且有选择的变动工作目录和索引,也用来在从历史仓库中复制文件到索引,而不动工作目录。

![](./_image/2016-07-14 20-31-39.png?r=64&f=1) 将工作区内容回退到远端的某个版本:git reset --hard <sha1-of-commit>

Revert

git revert will create a new commit that's the opposite (or inverse) of the given SHA. If the old commit is "matter", the new commit is "anti-matter"—anything removed in the old commit will be added in the new commit and anything added in the old commit will be removed in the new commit. This is Git's safest, most basic "undo" scenario, because it doesn't alter history—so you can now git push the new "inverse" commit to undo your mistaken commit.

git revert [--[no-]edit] [-n] [-m parent-number] [-s] [-S[<keyid>]] <commit>…​
git revert --continue
git revert --quit
git revert --abort

标签:reset,git,log,查看,反悔,commit,EMAIL
来源: https://www.cnblogs.com/igoodful/p/10721997.html