# learngit **Repository Path**: Yancl0416/learngit ## Basic Information - **Project Name**: learngit - **Description**: 学习git的仓库!!! - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-07-07 - **Last Updated**: 2025-12-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Gitee learn... 视频: 【全方位入门-2小时轻松玩转git】 https://www.bilibili.com/video/BV1ka411w7Dd/?p=16&share_source=copy_web&vd_source=8af85e60c2df9af1f0fd23935753a933 使用命令行重命名文件 git mv <旧的文件名> <新的文件名> 移动文件,也可以使用这个 git mv 命令 具体命令:it <旧的文件名> <要移动到的地方> change name and email version 1 git push 要在正确的目录下输入git指令 ## 14 不再追踪时候,如何撤销追踪 ```bash git reset HEAD main.c // 最后是文件名 ``` ## 15 版本回退到上一版本或者指定版本 回退到上一个版本 ```bash git reset --hard HAED^ // 几个^就是回退几个版本 ``` 回退到指定版本 ```bash git reset --hare // 回退到对应的版本号 ``` git reset 有三种模式 ```sh git reset --soft HEAD~1 // 将HEAD指针移动到前一个提交(HEAD~1),但保留工作目录和暂存区的更改;销最后一次提交,但提交的更改会保留在暂存区 git reset --mixed HEAD~1 // 将HEAD指针移动到前一个提交,重置暂存区,但保留工作目录的更改;销最后一次提交,提交的更改会保留在工作目录但不会在暂存区 git reset --hard HEAD~1 // 将HEAD指针移动到前一个提交,重置暂存区和工作目录;全删除最后一次提交的所有更改,包括工作目录的修改 ``` ## 16 想要将某一文件回退指定版本时 如何进行操作 git checkout -- <文件名> //只回退这一个文件到指定的版本 ## 17 想要修改内容之后推送至远程仓库如何进行操作? ```bash git push origin master git push origin main git push ``` ## 18 想要给每个版本创建一个独特的标签`tag`, 加在当前的版本(轻量标签) ```bash git tag V1.0 ``` 加在之前的版本 ```bash git tag V0.5 [commit ID] ``` 附注标签(git tag -a) ``` sh git tag -a V1.1 -m "version 1.1" ``` 添加完标签需要推送到远端 推送tag到远程仓库 ```bash git push origin V1.0 // 这个需要手动输入,不会自动推送 ``` 删除当前的tag ```bash git tag -d V0.5 ``` 上述操作只会删除本地的tag 如果想同步删除远程仓库的tag,需要加一条 ```sh git push origin :refs/tags/V0.5 ``` ## 19 切换、删除分支 创建分支 ```bash git branch test // 创建一个test分支 ``` 切换分支 ```bash git checkout test // 切换到test分支 ``` 删除分支(不能删除当前所在的分支,如果要删除,先切换到其他分支) ```bash git branch -d test ``` 合并分支 ```sh git merge //将test分支合并到当前所在的分支 ``` ## 撤销操作 ```sh git commit --amend ``` 执行了一次 git commit-tree 创建了一个全新的无父节点的提交对象,然后执行 git rebase --onto 操作,把最近的两题提交变基过来,只保留了三体提交记录 修改user.name ## 清除垃圾对象 ```sh git gc 清除垃圾对象 ``` 修改git blame 使能下面的选项,可以看到每一行代码的提交记录 Git › Blame › Editor Decoration: Enable 指定起始提交:使用onto后面跟随一个指定的提交,git rebase将从这个提交开始应用后续的提交。例如: ```sh $ git switch fixed $ git rebase --onto main C2 ``` 这将会将fixed分支上C2提交以后的提交应用到main分支上。也就是说,只有C2之后的提交会被应用到目标分支上。 2.指定起始和终止提交:使用onto后面跟随两个指定的提交,git rebase将从起始提交开始,应用到终止提交为止的所有提交。 ```sh $ git checkout fixed git rebase --onto main C2 C5 ``` 这将会将fixed分支上C2到C5之间的所有提交应用到main分支上。 将 main 分支强制指向当前 HEAD ```sh git branch -f main HEAD ``` ubuntu git test ubuntu git test