一、移除之前的远程库
git remote rm origin
二、添加远程库
git remote add origin https://gitee.com/XXX/XXXXXXX.git
三、push到分支中
git push -u origin master
一、创建版本库
(1)、git clone <url>
克隆远程版本库
(2)、git init
初始化本地版本库
二、修改和提交
(1)、git status
查看状态
(2)、git diff
查看变更内容
(3)、git add .
跟踪所有改动过的文件
(4)、git add <file>
跟踪指定文件
(5)、git mv <old> <new>
文件名更改
(6)、git rm <file>
删除文件
(7)、git rm --cached <file>
停止跟踪文件但不删除
(8)、git commit -m "commit message"
提交所有更新过的文件
(9)、git commit -- amend
修改最后一次提交
三、查看提交历史
(1)、git log
查看提交历史
(2)、git log -p <file>
查看指定文件的提交历史
(3)、git blame <file>
以列表方式查看指定文件
四、撤销
(1)、git reset --hard HEAD
撤销工作目录中的所有未提交文件的修改内容
(2)、git checkout HEAD <file>
撤销指定的未提交文件的修改内容
(3)、git revert <commit>
撤销指定的提交
五、分支与标签
(1)、git branch
显示所有本地分支
(2)、git checkout <branch/tag>
切换到指定分支或标签
(3)、git branch <new-branch>
创建新分支
(4)、
(5)、git tag
列出所有本地标签
(6)、git tag <tagname>
基于最新提交创建标签
(7)、git tag d <tagname>
删除标签
六、合并与衍合
(1)、git merga <branch>
合并指定分支到当前分支
(2)、git rebase <branch>
衍合指定分支到当前分支
七、远程操作
(1)、git remote -v
查看远程版本库信息
(2)、git remote show <remote>
查看指定远程版本库信息
(3)、git remote add <remote> <url>
添加远程版本库
八、错误提示
(一)github中的README.md文件不在本地代码目录中
C:UsersAdminDesktopmdNode>git push -u origin master
To https://gitee.com/devil_mask/md-node.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/devil_mask/md-node.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解答:此时我们需要git pull --rebase origin master
然后在进行push操作
(二)git commit提示Your branch is up-to-date with 'origin/master'.
(1)、我们就需要新建一个分支git branch newbranch
(2)、然后检查分支是否创建成功git branch
(3)、然后切换到你的新分支git checkout newbranch
(4)、将你的改动提交到新分支上git add . git commit -m "11111"
(5)、检查是否成功 git status
(6)、然后切换到主分支 git checkout master
(7)、然后将新分支提交的改动合并到主分支上 git merge newbranch
(8)、然后就可以push代码了 git push -u origin master
(9)、最后还可以删除这个分支git branch -D newbranch