1 本地有几个提交,但是不想要了,要完全同步服务器最新的提交
bash
git reset --hard origin/main
2 代码已经add了,想再用diff看看修改了哪些地方
bash
git diff --staged
3 分支不想要了,想删除本地和远程的分支
bash
#强制删除未合并的分支(丢弃未保存的修改)
git branch -D 分支名
#删除远程分支
git push origin --delete 分支名
4 提交的说明觉得不对劲,想修改一下
bash
git commit --amend -m "新的提交信息"
5 想撤销commit,但是保留修改
bash
git reset --soft HEAD~1
6 想只看某个文件的提交记录
bash
git log <文件路径>
7 新的修改想生成一个补丁丢给其他人同步
bash
#生成补丁
git show <commit-hash> > mypatch.diff
#应用补丁
git apply mypatch.diff
8 提交了一些代码,但是想新建一个分支,并且提交到远程
bash
#确认当前暂存状态
git status
#创建并切换到新分支
git checkout -b 新分支名
#在新分支上提交修改
git commit -m "你的提交信息"
#推送到远程仓库
git push -u origin 新分支名
9 merge的时候需要用nano编辑提交信息,改成vim
bash
# 改为 Vim
git config --global core.editor "vim"
# 查看当前配置
git config --global core.editor
10 想看看目前的仓库的远程地址
bash
git remote -v
11 想修改远程仓库的地址
bash
git remote set-url origin http://192.168.140.100:8899/veepai_changsha/ig02.git
12 合并其他分支到当前分支
bash
#确保你在个人分支上:
git checkout f/oushaojun
#获取远程最新信息:
git fetch origin
#将主分支合并到当前分支:
git merge origin/main