1、add文件时warning: LF will be replaced by CRLF in .idea/workspace.xml.

原因:windows中的换行符为 CRLF, 而在Linux下的换行符为LF,所以在执行add . 时会出现以下提示
解决:git config core.autocrlf false
2、GIT命令:
查看当前远程地址
bash
git remote -v
添加远程仓库地址:
bash
git remote add origin 远程仓库地址
修改远程地址:
bash
git remote set-url origin 远程仓库地址
删除远程仓库:
bash
$ git remote remove origin
在命令行上创建一个新的存储库
bash
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:zianji/springcloud.git
git push -u origin main
从命令行推送现有存储库
bash
git remote add origin git@github.com:zianji/springcloud.git
git branch -M main
git push -u origin main
GIT Remotes有多个仓库地址Start====

操作过程中不晓得啥操作多出来一个git,删除第二个多于的springcloud
End================
Git pull或push都会失败,找不到远程分支。Start====

根据上述最后一行提示,设置远程分支。
bash
git branch --set-upstream-to=origin/main main(远程仓库名称)
仍然失败,黄色提示内容:远程已经存在的分支,需要运行"gitfetch"来检索它。
git fetch在拉取代码过程中,git fetch会首先检查本地仓库和远程仓库的差异,检查哪些不存在于本地仓库,然后将这些变动的提交拉取到本地仓库,而不是本地工作目录,它不会自行将这些新数据合并到当前工作目录中,我们需要继续执行git merge才会把这些变动合并到当前工作目录。git pull直接获取远程的最新提交,直接拉取并合并到本地工作目录。
End===========================
3、回滚
git的版本回滚其实就是回滚不同的分区。git在本地有三大分区:工作区、暂存区、版本库。通过push之后推到远程仓库。
工作区:正在编写,还未add的部分。
暂存区:add后的代码。
版本库:commit后的代码
未add、commit的部分:工作区
准备环境,先新建testGitUse类。

进行add及commit操作:
commit之后:版本库
gituse提交因未push到远程仓库,所以显示的为本地master,同步到远端的提交分支会显示为origin/master.
3.1、commit之后未push之前回滚:


注意:undo commit只能从最后一次commit开始回滚,undo commit后会要求选择一个变更列表来存放回滚后的内容,可以自己新建一个,比如此处的gituse,也可以在下拉框里选择一个已经存在的,如果是自己新建的变更列表,勾选了set active选项,后续的变动也会存放到该变更列表中。
回滚后:
gituse提交操作没有了。

回滚后多了一个更新列表,再次操作如提交时选择此列表:

已push,进行回滚:
即将本地的代码版本回滚到指定版本
git中当前操作记录:


回滚方式一:
选中想要回滚的版本:
方式二:录入版本

回滚后继续操作将本地的版本用 git push -f
强推到远端。远端仓库即会回滚。

回滚后效果:
reset有几种模式:
soft,将版本回滚,工作区不动,暂存区=原来的+回滚后和回滚前的版本差异。
mixed,将版本回滚,回滚到了所有 git add 和 git commit 的命令执行之前。暂存区变为空,变更全部到了工作区。
hard,将版本回滚,将所有工作区和暂存区的文件修改全部清空,是真正的覆盖,不能找回了。
keep,将版本回滚,将所有commit的内容丢弃掉,未commit的内容保留。
合并代码最好不要使用rebase,它会改变基底,篡改提交记录,出问题不好追溯。建议使用merge,保存完成提交记录!!!