常用命令
git config credential.helper store 保存账号密码到本地
git init 初始化仓库
git add . 添加所有文件到版本控制中
git commit -m "init" 提交文件,提交信息为 “init”
git commit --amend 继上一次提交合并一起提交,提交信息为上一次提交信息
git remote add origin https://xxx.com 关联远程仓库地址
git push --set-upstream origin master 初次推送本地仓库至远程
git relog 查看 git 操作日志
git checkout -b commitId 已某个 commit 为基点创建 新分支
git apply commitId 应用某次提交的内容
git rebase
git pull
常见场景
初始化仓库
git init
关联远程仓库
如果是更改远程仓库地址,需要先删除远程仓库关联 git remote remove origin,然后再关联到新的远程仓库git remote add $url
切换分支
git switch other-branch 或者 git checkout other-branch ,两个命令都表示切换到 other-branch 分支
创建/删除分支
git checkout -b branchName基于当前HEAD创建新的分支 `branchNamegit branch -d branchName删除本地分支git push origin --delete orgin/branchName删除远程分支
对指定文件/文件夹 去除版本追踪
git rm --cached filePath--cached替换-f表示同时删除本地文件git add .git commit -m 'delete info'git push
恢复丢失的代码
git refloggit apply $commitId
添加/删除远程仓库地址
git remote add newOrigin remote_urlgit remove remote newOrigingit push --all newOrigingit push --tags newOrigin
查看未合并到主分支的分支
git branch -r --no-merged origin/master未合并到远程origin/master的所有分支git branch --no-merged main未合并到master的所有分支
常见问题
控制台中文乱码
git config --global core.quotepath false
更改文件夹名字 大小写无效
比如说 将 TempDirectory 改为 tempDirectory, 先将 TempDirectory 改为 tempDirectory_bak 然后提交。再将 tempDirectory_bak 改为 tempDirectory 之后提交,就可以改变远程仓库的 TempDirectory 目录名了。