git命令
git config --global user.name 名字
git config --global user.email 邮箱
$ git clone 地址
| 命令 | 作用 |
|---|---|
| git pull origin master | 拉取更新 |
| git checkout | 切换分支 |
| git add 文件名 | 添加到暂缓区 |
| git commit -m "备注" | 提交到本地库 |
| git push origin dev-cyw/master | 推送到远程仓库 |
| git reflog | 查看历史记录 |
shell
# 添加远程仓库
$ git remote add origin 网址xxx
#从远程仓库克隆
$ git clone 网址xxx
# 新建仓库
$ git init xxx
# 从已存在的文件夹创建
$ cd xxx
$ git init
# 添加到暂存区
$ git add <. / filename>
# 撤销
$ git reset HEAD <filename>
#查看本地库状态
$ git status
# 提交到本地仓库
$ git commit --m "备注"
# 还原到上个版本
$ git reset --soft HEAD^
# 推送到远程仓库
$ git push <远程主机> <本地分支>:<远程分支>
$ git push origin master
# 拉取更新
$ git pull <远程主机> <本地分支>:<远程分支>
$ git pull origin master
# 查看历史记录
$ git reflog
# 删除远程仓库
git push <remote_name> --delete <branch_name>
#eg:git push origin --delete feature-branch
shell
# 新建分支
$ git branch (-b) <branchname>
# 切换分支
$ git checkout <branchname>
# 分支列表
$ git branch
# 合并分支
$ git merge <branchname>
# 删除分支
$ git branch -d <branchname>
# 强制删除分支
$ git branch -D <branchname>
补充
修改提交备注:
执行 git commit --amend 命令,修改 commit 信息
1.按i进入编辑,:wq保存退出
2.执行 git push --force origin branch 命令,将修改后的 commit 推送到远程分支。
需要注意的是,使用 git push --force 命令会覆盖远程分支中的历史记录,因此需要谨慎操作。
取消上一次commit
使用 git reflog 查找撤销操作之前的 HEAD 位置: git reflog 命令会显示你的 HEAD 指针的历史记录,包括所有的提交和重置操作。你可以找到执行 git reset 之前的 HEAD 位置的哈希值。
bash
git reflog
然后,你可以使用 git reset 命令将 HEAD 指针重置回那个位置:
bash
git reset --hard <commit_hash>
撤销上一次远程提交
git reset --soft HEAD~1
git push origin xxx-dev --force