工作中常用到的git命令
-
# 在当前目录新建一个Git代码库$ git init
-
# 新建一个目录,将其初始化为Git代码库$ git init [project-name]
-
# 下载一个项目和它的整个代码历史$ git clone [url]
- 查看代码当前状态:$git status
- 提交本地代码push 到远程 git add . git commit -m "代码描述" git pull origin master 同步远程代码 git push origin master 推送本地最新代码到远程
- 列出所有本地分支 $ git branch # 列出所有本地分支和远程分支$ git branch -a 新建一个分支,但依然停留在当前分支 $ git branch [branch-name]
- # 新建一个分支,并切换到该分支 $ git checkout -b [branch] # 新建一个分支,指向指定commit $ git branch [branch] [commit]
- 合并指定分支到当前分支 $ git merge [branch] # 选择一个commit,合并进当前分支 $ git cherry-pick [commit]
- # 删除分支 $ git branch -d [branch-name] # 删除远程分支 $ git push origin --delete [branch-name]
- # 强行推送当前分支到远程仓库,即使有冲突 $ git push [remote] --force
-
查看提交记录 git log 恢复本地代码到指定版本 $ git reset --hard [commit] ps:合并代码时需要切换到要合并的版本执行git merge dev ---->git status ----继续