git 常用命令

日常开发中,git命令运用场景不少,在此记录下

1 分支

查看

查看本地分支:git branch

查看远程分支:git branch -r

查看所有分支:git branch -a

查看本地分支和远程分支的映射关系:git branch -vv

创建

创建本地分支:git checkout -b [branch_name]

创建远程分支:

  1. git checkout -b [branch_name]
  2. git push [origin] [branch_name] (origin是添加远程仓库时定义的,通常为origin)

关联

关联本地分支与远程分支:git branch --set-upstream-to=[origin]/[remote_branch_name]

推送并关联: git push -u [origin] [branch_name] (origin是添加远程仓库时定义的,通常为origin)

删除

删除本地分支:git branch -d [branch_name]

删除远程分支:git push [origin] -d [branch_name]

清理远程已经删除分支在本地的缓存:git remote prune [origin]

改名

修改本地分支名:git checkout -m [branch_name] [new_branch_name]

修改远程分支名:

  1. 修改本地 git branch -m [branch_name] [new_branch_name]
  2. 删除远程分支 git push [origin] -d [branch_name]
  3. 推送本地到远程git push -u [origin] [new_branch_name]

2 工作目录,暂存区,版本库

添加工作目录多个改动文件到暂存区:git add [file1] [file2] ...

添加工作目录所有改动文件到暂存区:git add .

添加暂存区多个文件到版本库:git commit [file1] [file2] ... -m [message]

添加暂存区所有文件到版本库:git commit -m [message]

将暂存区多个文件移动到工作目录:git reset [file1] [file2] ...

将暂存区所有文件移动到工作目录:git reset

将版本库中commit移动到暂存区:git reset --soft HEAD~[1] 1代表最近commit,2代表最近两个commit,以此类推

将版本库中commit移动到工作目录:git reset HEAD~[1] 1代表最近commit,2代表最近两个commit,以此类推

回退到最近几个commit:git reset --hard HEAD~[1] 1代表最近commit,2代表最近两个commit,以此类推

回退到指定版本:git reset --hard [commit_id]

作者:无心使然
链接:https://juejin.cn/post/7315405820673392679
来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

你可能感兴趣的:(scene,git,git,前端)