git常用命令


下载

 windows:
 	下载好之后,一路next就行
linux 
	arch/manjaro:	sudo pacman -S git
	debian/ubuntu:	sudo apt-get install git

配置

设置commit操作关联的用户名

git config --global user.name “[name]”

设置commit操作关联的邮箱地址

git config --global user.email “[email address]”


分支

创建一个新分支

git branch [branch-name]

切换到指定分支并更新工作目录(working directory)

git switch -c [branch-name]

将指定分支的历史合并到当前分支

git merge [branch]

删除指定分支

git branch -d [branch-name]


更改

查看当前分支修改日志

git log

查看文件状态

git status

列出文件的版本历史,包括重命名

git log --follow [file]

展示两个分支之间的内容差异

git diff [first-branch]…[second-branch]

输出指定commit的元数据和内容变化

git show [commit]

将文件进行快照处理用于版本控制

git add [file]

将文件快照永久地记录在版本历史中

git commit -m “[descriptive message]”


重新提交

撤销所有 [commit] 后的的提交,在本地保存更改

git reset [commit]

放弃所有历史,改回指定提交

git reset --hard [commit]


创建仓库

对于一个新仓库,要么本地创建然后推送到github,要么clone一个现有仓库
本地创建

git init

将本地仓库与一个 GitHub 上的空仓库连接起来

git remote add origin [url]

clone创建

git clone [url]

(clone包括所有的分支和提交)


同步更改

下载远端跟踪分支的所有历史

git fetch

将远端跟踪分支合并到当前本地分支

git merge

将所有本地分支提交上传到 GitHub

git pull

( git pull = git fetch + git merge )

posted @ 2021-11-04 02:49  TellMeYourStory  阅读(32)  评论(0)    收藏  举报