git学习笔记

git usage:
   git   [--version] [--help] [-C <path>] [-c name=value]
              [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
              [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
              [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
              <command> [<args>]

   The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty Git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and integrate with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG
******************/

cd <path>
git init
git add <filename>
git commit -m "<comment>"

git diff
git status
git log
git log --pretty=oneline
git reflog
git reset --hard HEAD/HEAD^/HEAD^^/<commit id>
--撤销修改
git checkout -- <filename> 回到最近一次git add  OR git commit 的状态
git reset HEAD <filename> 把暂存区的修改回退到工作区
--添加远程库
ssh-keygen -t rsa -C "youremail@example.com"
cd ~/.ssh/
cat id_rsa.pub
Add SSH Key
Create a new repository

git remote add origin git@github.com:tanke/"repositoryname"
git push -u origin master

warning: git remote rm origin
--克隆远程库
git clone git@github.com:tanke/"repositoryname"

--分支
git branch 查看分支
git branch <name> 创建分支
git checkout <name> 切换分支
git checkout -b <name> 创建并切换分支
git merge <name> 合并分支
git branch -d <name> 删除分支
--解决冲突
git log --graph 查看分区合并图
--BUG分支stash
git checkout -b dev
git add file
git stash
git checkout master
git checkout -b issue-101
git add file-bug
git commit -m "fix issue-101"
git checkout master
git merge --no-ff -m "fix issue-101" issue-101
git branch -d issue-101
git checkout dev
git stash list
git stash apply ...

git stash drop ...

git stash pop

--Feature(功能)分支
git checkout -b feature-tanke
git add ...
git commit -m "..."
git checkout dev
git merge --no-ff -m "..." feature-tanke
git branch -d feature-tanke
git branch -D feature-tanke
--多人协作
git push origin <branch-name>
git checkout -b origin/dev
git branch --set-upstream dev origin/dev
git pull 合并后修改
git branch -a 查看本地和远程所有分支
--标签管理
git tag v1.0 默认打在最新提交的commit HEAD
git tag v1.0 <MD5 number>
git tag 查看标签
git tag -a v1.0 -m "..." <MD5 number>
git show <tagname>查看标签信息
git tag -d v1.0 删除标签
git push origin v1.0 推送标签
git push origin --tags 推送全部标签
git tag -d v1.0                                //<-|
git push object :refs/tags/v1.0   //<-|——删除远程标签
--自定义Git
git config --global color.ui true
.gitignore 忽略特殊文件
git config --global alias.<new name> <default name>
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset
%s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"   配置别名
git last 最后一次提交的信息
--搭建Git服务器
sudo apt-get install git
sudo adduser git //创建一个git用户,用来运行git 服务
echo "登录用户的id_rsa.pub 公钥" >>/home/git/.ssh/authorized_keys //一行一个
cd <path>
sudo git init --bare sample.git //选定一个目录<path>作为Git仓库
sudo chown -R git:git sample.git //裸仓库无工作区,把owner改为git
vim /etc/passwd
git:x:1001:1001:,,,:/home/git:/bin/bash改为git:x:1001:1001:,,,/home/git:/use/bin/git-shell
git clone git@sever:/srv/sample.git 克隆远程仓库
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值