GIT常用指令

分支

# 新建一个分支 ,与 指定的远程分支 建立 追踪关系
git branch --track [branch] [remote-branch]

# 建立追踪关系,在现有分支与指定的远程分支之间
git branch --set-upstream [branch] [remote-branch]

# 选择一个 commit,合并进 当前分支
git cherry-pick [commit] 

# 删除远程分支
git push origin --delete [branch-name]
git branch -dr [remote/branch]

新建代码库

# 在当前目录新建一个Git代码库
git init

# 新建一个目录,将其初始化为Git代码库
git init [project-name]

# 下载一个项目和它的整个代码历史
git clone [url]

 代码提交

# 使用一次 新的 commit ,替代上一次提交
git commit -m "[message]"
# 如果代码没有发生任何新变化,则改写 上一次 commit 的 提交信息
git commit --amend m [message]

远程同步

# 下载远程仓库 
git fetch [remote]

# 显示所有远程仓库
git remote -v

# 增加一个新的远程仓库,并命名
git remote add [shortname] [url]

# 强行推送当前分支到远程分支,即使有冲突
git push [remote] --force

删除文件

# 删除工作区文件,并将删除的文件放入缓存区
git rm [file1] [file2] ... 

# 停止追踪 指定文件, 但该文件会保留在工作区
git rm --cached[file]

# 改名文件,并且将这个改名放入暂存区
git mv [file-original] [file-renamed]

撤销

# 恢复暂存区的指定文件到工作区
git checkout [file]

# 恢复暂存区的所有文件到工作区
git checkout .

# 重置暂存区的指定文件,与上一次commit 保持一致, 但工作区不变
git reset --hard

# 重置当前分支的指针为指定 commit,同时重置暂存区和工作区,与指定commit 一致
git reset --hard [commit]

# 重置当前HEAD为指定commit ,但保持暂存区和工作区不变
git reset --keep [commit]

# 新建一个commit ,用来撤销指定commit 
# 后者但所有变化豆浆被前者抵消,并且应用到当前分支
git revert [commit]

#暂时将为提交到变化移除,稍后再移入
git stash
git stash  pop

 

posted @ 2021-05-17 15:13  晴很快乐  阅读(74)  评论(0)    收藏  举报