Git参考手册
1. Git 配置命令
-
设置名称:
$ git config--global user.name "用户名"
- 设置电子邮件:
$ $ git config--global user.email" himanshudubey481@gmail.com"
- 设置默认编辑器:
$ git config--global core.editor Vim
- 检查设置:
$ git config-list
-
Git别名 为每个命令设置别名
$ git config--global alias.co checkout $ git config--global alias.br branch $ git config--global alias.ci commit $ git config--global alias.st status
2.初始化项目(Starting a project)
-
Git初始化 创建本地存储库:
$ git init <仓库名称>
-
Git克隆 制作服务器存储库的本地副本。
$ git clone <远程URL>
3.本地变化(Local changes)
-
Git添加文件到暂存(索引)区域:
$ git add Filename
-
Git增加所有文件添加到暂存(索引)区域:
$ git add *
-
Git 文件提交 将文件永久快照在版本历史记录中。
$ git commit-m "提交消息"
4.追踪变更(Track changes)
-
Git diff 跟踪尚未上演的更改:
$ git diff
- 跟踪已上演但尚未落实的更改:
$ git diff--staged
- 提交文件后跟踪更改:
$ git diff HEAD
- 跟踪两次提交之间的更改:
$ git diff Git Diff Branches: $ git diff < branch 2>
-
Git状态
显示工作目录和暂存区的状态。
$ git status
-
Git Show 查看对象
$ git show <选项> <对象>
5.提交历史(Commit History)
-
Git log
显示最近的提交和头部的状态:$ git log
- 将输出显示为每行一次提交:
$ git log-oneline
- 显示已修改的文件:
$ git log-stat
- 显示修改后的文件的位置:
$ git log-p
-
Git blame
在文件的每一行上显示修改:$ git blame <file name>
6.忽略文件(Ignoring)
-
.gitignore
指定Git应该忽略的故意未跟踪的文件。创建.gitignore:$ touch .gitignore List the ignored files: $ git ls-files-i--exclude-standard
7.分支(Branching)
-
git branch列表分支:
$ git branch
$ git branch-dDelete a remote Branch:
$ git push origin-deleteRename Branch:
$ git branch-m -
Git checkout
在存储库中的分支之间切换,切换到特定分支:$ git checkout -
创建一个新分支并切换到它: $ git checkout-b Checkout a Remote branch: $ git checkout -
Git stash
切换分支而不提交当前分支,命令可用于临时保存和回复修改$ git stash - 用消息保存存储:
$ git stash save "" 检查存储的存储: $ git stash list -
重新应用刚刚stash的更改: $ git stash apply -
跟踪stash及其变化: $ git stash show -
重新应用以前的提交: $ git stash pop -
从队列中删除最新的存储: $ git stash drop 一次删除所有可用的存储区: $ git stash clear -
将工作隐藏在单独的分支上: $ git stash branch -
Git cherry pic
应用一些现有提交引入的更改:$ git cherry-pick
8.合并(Merging)
-
Git merge
将指定的提交合并到当前活动的分支中: $ git merge commit -
Git rebase
将来自不同分支的一系列提交应用于最终提交。
继续rebasing进程:$ git rebase $ git rebase-continue # Abort the rebasing process: $ git rebase--skip -
Git interactive rebase
允许对现有提交执行各种操作,例如编辑,重写,重新排序等。$ git rebase-i
9.远程(Remote)
-
Git remote
检查远程服务器的配置:$ git remote-v - 增加远程存储库:
$ git remote add <short_name> <remote_URL> -
从远程服务器获取数据: $ git fetch <远程> -
从存储库中删除远程连接: $ git remote rm <目标> -
重命名远程服务器: $ git remote rename <旧名称> <新名称> -
显示有关远程其他信息: $ git remote show <远程> -
更改远程路径: $ git remote set-url <远程名称> -
Git origin master
将数据推送到远程服务器:$ git push origin master Pull data from remote server: $ git pull origin master
10.推送更新(Pushing Updates)
-
Git push
将提交从本地存储库传输到远程服务器。将数据推送到远程服务器:$ git push <远程> <分支> $ git push-f -
通过push命令删除远程分支: $ git push origin-delete edited
11.拉取更新(Pulling updates)
-
Git pull
从服务器提取数据:$ git pull origin master - 拉取一个远程分支:
$ git pull <远程分支URL> -
Git fetch
从一个或多个存储库下载分支和标签。获取远程存储库:$ git fetch <分支网址> <分支名称> -
同时获取所有分支: $ git fetch-all -
同步本地存储库: $git fetch origin
12.撤消更改(Undo changes)
-
Git revert
撤消更改:$git revert branch_name -
Git reset
重置更改:$ git reset-hard $ git reset-soft: $ git reset--mixed
13.删除文件(Removing file)
- 从工作树和索引中删除文件:
$ git rm <file Name> - 从Git中删除文件,但将文件保留在本地存储库中:
$ git rm--cached
祝学习愉快! (发现内容有误?请选中要编辑的内容 -> 右键 -> 修改 -> 提交!帮助我们改进教程质量)
精选教程推荐
👇 以下精选教程可能对您有帮助,拓展您的技术视野
暂无学习笔记,成为第一个分享的人吧!
您的笔记将帮助成千上万的学习者