Git小笔记

撤销操做

  • git add 错误

git add 若是添加错了文件的话须要撤销的话git

git reset HEAD 会直接撤销上一次操做全部的addfetch

git reset HEAD filename 能够撤销一个文件的addcode

git reset HEAD --hard 会回到上一次的commit的状态it

  • git commit 错误

若是已经commit了,这个时候文件已经在本地仓库 先使用git log 查看节点 commit xxxxxxxxxxxxxxxxxxxxxxxxxx 而后 git reset commit_idclass

尚未 push 也就是 repo upload 的时候file

git reset commit_id 回退到上一个 提交的节点 代码仍是原来你修改的 git reset –hard commit_id 至关于把代码从远程仓库拉下来,这时候会回到上一个commit节点, 代码也会变成上一个版本的 也可使用git reset HEAD^ --hard 这样会回到上上一次的commit,本次的commit会被丢掉下载

  • 若是要是 提交了之后,可使用 git revert

git revert是提交一个新的版本,将须要revert的版本的内容再反向修改回去,版本会递增,不影响以前提交的内容。引用

还原已经提交的修改 这次操做以前和以后的commit和history都会保留,而且把此次撤销做为一次最新的提交 git revert HEAD 撤销前一次 commit git revert HEAD^ 撤销前前一次 commit git revert commit-id 撤销指定的版本,撤销也会做为一次提交进行保存di

git pull && git fetch

git pull将下载提交到当前分支。 git pull其实是 fetchmerge 命令的组合。文件

git fetch将从远程获取最新的引用。 git fetch --all 能够得到远程全部分支的变更

相关文章
相关标签/搜索