Git 使用总结

检出分支或者tag代码:git checkout <branchName>/<tag>

从远程代码分支(标签)或者本地代码分支(标签)检出代码创建新的分支

  git checkout -b [newBranchName]  [<branchName> | <tagName> ]

 删除远程分支:git push -d origin <remoteBranchName> 

 标签:

可以执行如下命令以创建一个叫做 1.0.0 的标签:
git tag 1.0.0 1b2e1d63ff
1b2e1d63ff 是你想要标记的提交 ID 的前 10 位字符。使用如下命令获取提交 ID:
git log
你也可以用该提交 ID 的少一些的前几位,只要它是唯一的

git push origin  [branch_name|tag]

如果本地分支或者标签都存在1.0.0,git push origin 1.0.0 无法提交。

 

查看当前分支日志:git log

查看本地指定分支日志:git log <localBranchName>

查看远程分支日志: git log  remotes/origin/<remoteBranchName>(也可用登录远程仓库查看)

查看回滚或者删除分支(git log上查不到的日志):git reflog

 

回滚整个版本:

git reset --hard tag_name/commit_id/HEAD :回滚到tag_name或者commit-id,将commit-id之后提交的commit都去除,

如果误操作导致退回到之前的版本,用git log是查不到reset日志,得用git reflog查到reset日志,可以再恢复到现在的版本git reset --hard(具体操作见:https://blog.csdn.net/magiclyj/article/details/81475601)。

git push -f  remote  <remoteBranchName> 可以强制将远程仓库分支更新为回滚的版本。

回滚某个文件:

  两种方法:

    1、git checkout  commit_id a.txt ==> git push

    2、git reset commit_id a.txt==>git status(会发现缓存区改变了,工作区没有改变) ==>git commit -m 'reset file xxxx' ==>git checkout  -- a.txt(工作区变了)

推荐GIT教程:

https://www.yiibai.com/git

https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000#0

 

posted @ 2019-02-23 18:40  feibazhf  阅读(134)  评论(0编辑  收藏  举报