美文网首页
git 常用命令

git 常用命令

作者: LingSun | 来源:发表于2020-01-13 11:17 被阅读0次

git diff 比较分支
git status 查看状态
git add .
git commit -m '提交描述'
git log 查看日志
git show '提交的编号'

git branch // 查看所有分支
git pull origin '分支名'
git push origin '分支名'

git checkout '切换的分支名'
git fetch // 拉取远程的所有分支到本地

git stash // 将当前修改的内容放一边,再切换分支
git stash pop // 切换分支后,将刚才git stash 内容释放出来

修改分支名步骤:

git checkout old_branch // 先切换到需要修改的分支
git branch -m old_branch new_branch // 修改本地分支名
git push --delete origin old_branch // 删除原来的远程分支名
git push origin new_branch // 将新分支提交到远程

撤销,放弃本地修改

1、未使用 git add 缓存代码时:
git checkout --filepathname // 放弃 filepathname文件的修改
git checkout . // 放弃所有修改
2、已经使用了 git add 缓存了代码:
git reset HEAD filepathname // 回退到 git add 状态
git reset HEAD . //
这两个命令还原本地修改,只是回到了如 1 的状态
3、已经用 git commit 提交了代码:
git reset --hard HEAD^ // 回退到上一次commit的状态
git reset --hard commitid // 回退到任意版本

相关文章

网友评论

      本文标题:git 常用命令

      本文链接:https://www.haomeiwen.com/subject/xkiqactx.html