1.git 常用命令#
1.常用#
Copy
$ git remote add origin git@github.com:yeszao/dofiler.git
$ git pull origin master
$ git push origin master
$ git fetch origin
$ git branch
$ git checkout master
$ git checkout -b dev
$ git commit -m "first version"
$ git status
$ git log
$ git config --global core.editor vim
$ git config core.ignorecase false
$ git config --global user.name "YOUR NAME"
$ git config --global user.email "YOUR EMAIL ADDRESS"
2.别名 alias#
Copy
$ git config --global alias.br="branch"
$ git config --global alias.co="checkout"
$ git config --global alias.cb="checkout -b"
$ git config --global alias.cm="commit -m"
$ git config --global alias.st="status"
$ git config --global alias.pullm="pull origin master"
$ git config --global alias.pushm="push origin master"
$ git config --global alias.log="git log --oneline --graph --decorate --color=always"
$ git config --global alias.logg="git log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative"
3.创建版本库#
Copy
$ git clone <url>
$ git init
4.修改和提交#
Copy
$ git status
$ git diff
$ git add .
$ git add <file>
$ git mv <old> <new>
$ git rm <file>
$ git rm --cached <file>
$ git commit -m “commit message”
$ git commit --amend
5.查看历史#
Copy
$ git log
$ git log -p <file>
$ git blame <file>
6.撤销#
Copy
$ git reset --hard HEAD
$ git reset --hard <version>
$ git checkout HEAD <file>
$ git checkout -- <file>
$ git revert <commit>
7.分支与标签#
Copy
$ git branch
$ git checkout <branch/tag>
$ git branch <new-branch>
$ git branch -d <branch>
$ git tag
$ git tag <tagname>
$ git tag -a "v1.0" -m "一些说明"
$ git tag -d <tagname>
$ git checkout dev
$ git cherry-pick 62ecb3
8.合并与衍合#
Copy
$ git merge <branch>
$ git merge --abort
$ git merge dev -Xtheirs
$ git rebase <branch>
9.远程操作#
Copy
$ git remote -v
$ git remote show <remote>
$ git remote add <remote> <url>
$ git remote remove <remote>
$ git fetch <remote>
$ git pull <remote> <branch>
$ git push <remote> <branch>
$ git push <remote> :<branch/tag-name>
$ git push --tags
10.打包#
Copy
$ git archive --format=zip --output ../file.zip master
$ git archive --format=zip --output ../v1.2.zip v1.2
$ git archive --format=zip v1.2 > ../v1.2.zip
11.全局和局部配置#
- 全局配置保存在:
$Home/.gitconfig
- 本地仓库配置保存在:
.git/config
12.远程与本地合并#
Copy
$ git init
$ git add .
$ git commit -m "add local source"
$ git pull origin master
$ git merge master
$ git push -u origin master
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 推荐几款开源且免费的 .NET MAUI 组件库
· 实操Deepseek接入个人知识库
· 易语言 —— 开山篇
· Trae初体验