git 撤销操作

来源:互联网 发布:怎么开发app软件 编辑:程序博客网 时间:2024/05/16 13:53

head  index(stage) wroking 图示


一:撤销添加到add,但是还没有commit的文件

git reset HEAD FILENAME

二:追加文件到还没有push的commit中

$ git commit -m 'initial commit'$ git add forgotten_file$ git commit --amend

三:撤销还没有push的commit的修改

先git log  找到要回退的hash

在 git reset  --参数(如下)  hash_id

$ git reset -husage: git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]   or: git reset [-q] <tree-ish> [--] <paths>...   or: git reset --patch [<tree-ish>] [--] [<paths>...]    -q, --quiet           be quiet, only report errors     --mixed               reset HEAD and index  //仓库和暂存区回退,本地不变    --soft                reset only HEAD  //仓库回退,暂存区和本地不变    --hard                reset HEAD, index and working tree //仓库,暂存区和本区全部回退    --merge               reset HEAD, index and working tree //仓库,暂存区和本区全部回退    --keep                reset HEAD but keep local changes //字面意思是本地不变,但是实测本地回退了,所以慎用    -p, --patch           select hunks interactively    -N, --intent-to-add   record only the fact that removed paths will be added later



0 0
原创粉丝点击