命令行
初始化项目
git init
工作区 => 暂存区
git add 文件名
git add *
git commit -m "这次提交的描述"
查看当前工作区状态
git status
从暂存区恢复到工作区
git checkout 文件名
查看工作区和暂存区的区别
git diff
查看提交的历史版本
git log
git log
恢复指定版本到文件
git reset --hard 版本号
第一次代码提交(暂存区=>远程仓库)
echo "# nextjs-users-manage" >> README.md
git init
git add *
git commit -m "first commit"
git branch -m main
git remote add origin https:
git push -u origin master(分支)
git push -f origin master
完整操作
git add *
git commit -m "操作描述"
git status
git push
从远程仓库克隆项目到本地
git clone 仓库地址
从远程仓库更新代码到本地
git pull
切换分支
git checkout 分支名
合并分支
git merge dev
给当前的commit创建新的标签
git tag <tag_name>
分支总结
git branch
git branch -vv
git branch -r
git branch -a
git remote -v
git remote show origin
git fetch
git fetch --prune
git branch <name>
git checkout <name>
git checkout -b <name>
git merge <name>
git log --online --graph
git branch -d <name>
git tag <tag_name>
git tag -d <tag_name>
额外命令
tree .git
本地仓库和远程仓库关联
git remote add origin <你的远程仓库地址>
git push -u origin master
撤销git add 操作
git add
git reset
从远程仓库下拉到本地,忽略覆盖更改过本地公共配置文件
git stash
git pull
git stash pop
多个分支代码拉取与推送
git add *
git commit -m "操作描述"
git push origin dev_yu
git stash
git pull origin dev
git add *
git commit -m "merge dev to dev_yu"
git push origin dev_yu
git checkout dev
git pull origin dev_yu
git push origin dev
git checkout dev_yu
git stash pop
常见问题
- 问题1: 'Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch'
press "i" (i for insert)
write your merge message
press "esc" (escape)
write ":wq" (write & quit)
then press enter