本地新建(无仓库),拉取远程
git clone http://XXXXX.git
git branch -a 查看所有分支
git branch 查看本地有哪些分支
# 如果有新分支 git branch -a 查看不到就需要更新一下索引
git
tchgit checkout 分支名 切换分支
不要本地分支的操作,拉取远端覆盖本地分支
在使用Git的过程中,有些时候我们只想要git服务器中的最新版本的项目,对于本地的项目中修改不做任何理会,就需要用到Git pull的强制覆盖,具体代码如下:
git fetch --all
git reset --hard origin/dev
git pull XXX
我是与远程dev分支一致,你们可以根据自己的需求进行修改分支。
删除分支
删除远程分支
git push origin --delete xxxx
删除本地分支
git branch -d devpushpush
强制删除
git branch -D xxx
删除某个已在分支的文件使用 git commit -m "备注" 就能直接把删除记录加入分支
基于当前本地分支创建新分支
git checkout -b xxxx
基于远端创建新分支
git checkout -b xxxx origin/xxx
本地XXX分支推送到远端XXX分支
git push -u origin xxxx
当前分支合并A分支
git merge A
更改本地或远程分支名称
git branch -m old_branch new_branch # Rename branch locally
先改本地再更改远程
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
删除了本地的文件,想重新远端拉取
git checkout 完整链接文件名
git checkout . 拉取当前文件
锁住当前本地分支,修改其他分支后,再回来恢复
git stash 保存
git stash pop 还原(不保留记录,能好用)
git stash --apply 还原(保留记录,特殊情况用)
放弃某个文件的修改,重新更换成分支的文件
git checkout -- xxx // 还没 git add 注意有 -- ,并且 -- 和文件之间有空格
# 全部文件回退为分支代码
git checkout .
#已经git add了
git reset HEAD readme.md // 单个文件
git reset HEAD . // 全部文件
查看当前分支的父分支
git reflog show 当前分支名 # git reflog show feature/107
git diff 文件路径 # 可以查看本地代码比较分支代码
# 查看指定分支代码
git log # 查看分支
git checkout 哈希值
git checkout 分支名 # 返回主分支
对某个文件或者版本回滚:可以把文件回退到某个版本
参考:https://blog.csdn.net/gf771115/article/details/116092624
git log ngb/web/core/frame/themes/ngb/hn/login.jsp
git reset 98f73b8a000ec2a57c25048b8cf9f5cf978d9447 ngb/web/core/frame/themes/ngb/hn/login.jsp
git diff
git commit -m "回滚" # 不需要 git add
git status
git push
history
git restore 文件名 //恢复已修改的内容 例如:git restore test.txt