美文网首页程序员
Git 常用命令

Git 常用命令

作者: 就叫吴昊 | 来源:发表于2020-10-05 00:37 被阅读0次
# 初始化
git init

# 获取一个项目
git clone URL

# 将已有项目添加到git中
git remote add origin URL

# 将已修改的文件放入暂存区中
git add <file name>

# 将暂存区的文件移回工作区
git restore --staged <file>

# 查看状态
git status

# 提交修改并加标题
git commit -m "<title>"

# 将本地push到库中
git push -u origin master

# 有时候我们提交完了才发现漏掉了几个文件没有添加,或者提交信息写错了。 
# 此时,可以运行带有 --amend 选项的提交命令来重新提交:
git commit --amend

# 放弃已修改的文件,使其恢复到上一次提交的样子
git checkout -- <file>

# 这个命令会访问远程仓库,从中拉取所有本地还没有的数据
git fetch <remote>

# 创建分支
git branch <name>

# 切换分支
git checkout <branch name>

# 合并分支
git merge <branch name >

# 删除分支
git branch -d <name>

# git 回滚到之前某次commit
git reset –hard 8ff24a6803173208f3e606e32dfcf82db9ac84d8

# git误commit文件后 删除
git rm -r --cached

# git 获取最新代码并合并
git pull

相关文章

网友评论

    本文标题:Git 常用命令

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