git:command

 

工具

TortoiseGit , Sourcetree ,git-flow

配置

设置提交代码时的用户信息

git config [--global] user.name "[name]"
git config [--global] user.email "[email address]"

查看当前用户(global)配置

git config --global  --list

查看当前仓库配置信息

git config --local  --list

查看系统config

git config --system --list

gitk图形界面中文解决乱码情况

git config --global gui.encoding utf-8

gitk的使用

gitk --all

git clone --bare my_project my_project.git

现在你拥有了一份Git目录的数据副本,它存放在my_project.git目录下。

大致等同于:(生成配置文件有微小差异)

cp -Rf my_project/.git my_project.git

将裸仓库放置在服务器上:

scp -r my_project.git user@git.example.com:/srv/git

分支管理

git push --set-upstream origin dev # 推送到远程分支

# 合并终止

git merge develop

git merge --abort          git reset --hard HEAD

# 存储

git stash

git stash list

git stash apply [--index] stash@{0}

git stash drop stash@{0}

# rebase, 会把某个分支上所有提交的更改在另一个分支上重现一遍

把某条开发分支线上的工作在另一个分支上按顺序重现,而合并 [merge] 操作则是找出两个分支的末端,并把它们合并到一起

git checkout experiment

git rebase master

# 列出所有本地的分支列表及每个分支跟踪的远程分支信息,以及本地分支是否领先或落后于远程分支信息

git branch -vv

# 从develop创建分支myfeature

git checkout -b myfeature develop

# origin/serverfix合并当前本地分支

git fetch origin

git merge origin/serverfix

# 基于origin/serverfix创建本地分支

git checkout -b serverfix origin/serverfix

 # 列出本地所有分支

git branch

# 列出远程所有分支

git branch -r

# 列出所有本地分支和远程分支

git branch -a

# 新建一个分支,但依然停留在当前分支

git branch [命名空间]/[branch-name] [master]

# 新建一个分支,指向指定commit

git branch [branch] [commit]

# 新建一个分支,与指定的远程的分支建立追踪关系

git branch --track [branch] [remote-branch]

git branch --track dev origin/feature/***

git branch --unset-upstream #撤销追踪关系

# 切换到指定分支,并更新工作区

git checkout [branch-name]

# 切换到上一个分支

git checkout -

# 建立追踪关系,在现有分支与指定的远程分支之间

git branch --set-upstream-to [branch] [remote-branch]

git branch -u origin/branch

# 合并指定根治到当前分支

git merge [branch]

# 选择一个commit,合并到当前分支

git cherry-pik [commit]

# 删除分支

git branch -d [branch-name]

git branch -d test
git branch -D test(强制)
git branch -a | grep -v -E 'master|dev' | xargs git branch -D    //批量删除本地分支,正则表达式(-E)
xargs : 可以通过管道接受字符串,并将接收到的字符串通过空格分割成许多参数(默认情况下是通过空格分割) 然后将参数传递给其后面的命令,作为后面命令的命令行参数

# 删除远程分支

git push origin --delete [branch-name]

git branch -dr [remote/branch]

git branch -r -d origin/test

git push origin :test

标签

# 列出所有tag

git tag

# 新建一个tag在当前commit

git tag [tag]

# 新建一个tag在指定commit

git tag [tag] [commit]

# 删除本地tag

git tag -d [tag]

# 删除远程tag

git push origin :refs/tags/[tagName]

# 查看tag信息

git show [tag]

# 提交指定tag

git push [remote] [tag]

# 提交所有tag

git push [remote] --tags

# 新建一个分支,指向某个tag

git checkout -b [branch] [tag]

查看信息

# 显示工作区和暂存区的差异

git diff

# 显示暂存区和上一个commit的差异

git diff --cached [file]

# 显示工作区与当前分支最新commit之间的差异

git diff HEAD

# 显示某次提交的源数据和内容变化

git show [commit]

# 显示某次提交时,某个文件的内容

git show [commit]:[filename]

# 显示当前分支的最近几次提交

git reflog

远程同步

# 抓取远程仓库更新,下载远程仓库的所有变动

git fetch [remote]

# 显示每个分支的最新提交

git remote -v

# 要查看那些分支已经/[尚未]并入当前分支

git branch --merged / [--no-merged]

# 显示某个远程仓库的信息

git remote show [remote]

# 增加一个新的远程仓库,并命名

git remote add [origin] [url]

git remote rm origin
git remote add origin [url]

# 取回远程仓库的变化,并与本地分支合并

git pull [remote] [branch]

# 上传本地指定分支到远程仓库

推送你的更新到远程服务器,语法为 git push [远程名] [本地分支]:[远程分支]

git push [remote] [branch]

# 推送所有分支到远程仓库

git push [remote] --all

撤销

# 恢复暂存区的指定文件到工作区

git checkout [file]

# 恢复某个commit的指定文件到暂存区和工作区

git checkout [commit] [file]

# 恢复暂存区的所有文件到工作区

git checkout .

# 重置暂存区的指定文件,与上一次commit保持一致,但工作区不变

git reset [file]

# 重置暂存区与工作区,与上一次commit保持一致

git reset --hard

# 重置当前分支的指针为指定commit,同时重置暂存区,但工作区不变

git reset [commit]

# 重置当前分支的HEAD为指定commit,同时重置暂存区和工作区,与指定commit一致

gti reset --hard [commit]

# 重置当前HEAD为指定commit,但保持暂存区和工作区不变

git reset --keep [commit]

# 撤销指定commit,后者的所有变化豆浆被前者抵消,并且应用到当前分支

git revert [commit]

# 暂时将未提交的变化移除,稍后再移入继续工作

git stash

git stash pop

 

有一种撤销操作的常见使用场景,是提交之后才发现自己忘记了添加某些文件信息,如果这时你想重新尝试提交,可以使用--amend选项:

git commit -m 'initial commit' 

git add forgotten_file

git commit --amend

最终只是产生了一个提交,因为第二个提交命令修正了第一个提交的结果

将文件移除暂存区(添加文件到暂存区git add .)

 Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

 

想删除当前工作目录下的未跟踪文件以及文件夹运行:

git clean -df

which -a git

git log --oneline --decorate --graph --all


git stash
git stash apply --index stash@{0}
git stash list

工作区与暂存区
git diff

暂存区与本地仓库
git diff --cached

撤销
git checkout 
git reset
git clean
git revert

重写历史记录
git commit --amend
git rebase
git reset
git reflog

查看对比历史
git show
git log
git diff

GIT本地分支与合并
git branch
git tag
git checkout
git stash
git merge

======================================

.gitignore

git rm -r --cached .

git add .

git commit -m 'update .gitignore'

====================================================================

--------------------------

--

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值