linux,  tools,  ubuntu

GIT

Git

GIT 是分布式代码版本管理系统

Git 操作

SSH Key

创建ssh key, linux 用户目录下.git存在两个文件 id_rsa 和 id_rsa.pub

ssh-keygen -t rsa -C "youremail@example.com"

增加ssh key 到remote repo

Such as github: open account setting ssh key > > > interface:
add ssh key
pass the id_rsa.pub
click add key.

Git 安装和配置

ubuntu 安装
# apt-get install git
Git 安装之后,还需要一些配置,如你提交代码时的一些信息:提交人是谁? 提交人的邮箱是多少?别人就可以通过这些信息找到你。 

git config --global user.email mail@mail.com
git config --global user.name "xxxxx"

Git 可以通过不同的参数,灵活设置这些配置的作用范围

  • –global : 配置 ~./.gitconfig 文件,对当前用户等下的所有仓库有效。
  • –system: 配置 /etc/gitconfig文件,对当前系统下的所有用户有效。
  • 无参数: 配置 .git/config 文件,只对当前仓库有效。 

使用remote repo

  1. git remote add: add remote repo in local
    git remote add origin git@github.com:michaelliao/learngit.git
  2. git push :git push local master to remote origin/master
    -u can link the local and remote master
    git push -u origin master
  3. git clone: clone remote repo
    git clone git@github.com:michaelliao/gitskills.git
  4. git remote remove
    git remote remove origin

Git server

refer to here

refer here to build the local repo.

local server build as below:

please refer the link and build as below:

  1. create a bare repo
    git init --bare /ext1/repo-server/test.git
    
  2. push a repo
    git remote add origin fredy@localhost:/ext1/repo-server/test.git
    git push origin master
    
  3. pull a repo
    $ git clone fredy@localhost:/ext1/repo-server/test.git
    

branch manage

  • git checkout -b : create branch
$ git checkout -b dev
Switched to a new branch 'dev'
  • git merge : combine the branch to current branch
git merge dev
  • git checkout and git switch : switch branch
git switch -c  master
  • git branch -d : delete branch
git branch -d <name>

solving conflict

  • merge
$ git merge feature1
Auto-merging readme.txt
CONFLICT (content): Merge conflict in readme.txt
Automatic merge failed; fix conflicts and then commit the result.

note: Git will Fast forward mode,but in this mode. when delete this  branch, will lost this branch message. so please use --no-ff to disable fast forward mode.
$ git merge --no-ff -m "merge with no-ff" dev
  • git status : find diff
git status
  • modify the diff
  • check the modify
git log --graph --pretty=oneline --abbrev-commit
  • delete the branch
    git branch -d feature1
    

solving conflict multi people

  1. git push :conflict
  2. git pull
  3. solve conflict
  4. git push

solve git am conflict

1. git am --signoff xxx.patch. or git apply has error.
2. git  apply --reject xxx.patch.
3. modify the conflict.
4. git add 
5. git am --resolved

bug branch:

  1. Saving current work

    git stash

  2. check the current status git status

  3. create new branch and merge

  4. back to work

    “`
    git stash list
    stash@{0}: WIP on dev: f52c633 add merge
    </p></li>
    </ol>

    <p> git stash pop

    “`

    remote git

    git remote set-url origin ssh://git@bitbucket.com/~/vsdk0304-driver.git
    git push -u origin --all
    git push origin --tags
    

    delete cache

    git rm -r --cached .
    git add .
    git commit -m 'update .gitignore'
    git ignore
    git check-ignore : rule check
    

    Git repo

    You have an empty repository,To get started you will need to run these commands in your terminal.

    1. New to Git? Learn the basic Git commands,Configure Git for the first time
    git config --global user.name "xxxx"
    git config --global user.email "xxxxx"
    

    Working with your repository I just want to clone this repository If you want to simply clone this empty repository then run this command in your terminal.

    git clone ssh://git@bitbucket.com/~xxxxx/manifest.git
    

    My code is ready to be pushed If you already have code ready to be pushed to this repository then run this in your terminal.

    cd existing-project
    git init
    git add --all
    git commit -m "Initial Commit"
    git remote add origin ssh://git@bitbucket.com/~xxxxx/manifest.git
    git push -u origin master
    

    My code is already tracked by Git If your code is already tracked by Git then set this repository as your “origin” to push to.

    cd existing-project
    git remote set-url origin ssh://git@bitbucket.com/~axxxx/manifest.git
    git push -u origin --all
    git push origin --tags
    

    Git 命令

    git log

    git log --pretty=oneline
    git reset --hard HEAD^
    git log --grep=word
    git log --author=word
    git log 
    git reflog 
    

    git reset

    git reset --hard 1094a
    

    git status

    git status
    

    git commit

    git commit
    

    git checkout

    git checkout
    git checkout -- file
    

    git diff

    git diff HEAD -- readme.txt 
    

    git rm

    git rm --cached *
    

    git push

    git push -u origin --all
    git push origin --tags
    

    git tag

    1. create tag
    git tag  v1.0
    # tag on special commit
    $ git tag v0.9 f52c633
    # tag and commits
     git tag -a v0.1 -m "version 0.1 released" 1094adb
    
    1. git tag check the tag

    2. git show: show the tag

    3. delete tag

      $ git tag -d v0.1

    4. push tags git push origin --tags

    5. delete remote tag

      git push origin :refs/tags/v0.9

    git archive

    - git archive --format=zip HEAD `git diff --name-only 31967c5   ad06de9` > a.zip
    

    git mudule

    command

    git submodule [--quiet] add [<options>] [--] <repository> [<path>]
    git submodule [--quiet] status [--cached] [--recursive] [--] [<path>…​]
    git submodule [--quiet] init [--] [<path>…​]
    git submodule [--quiet] deinit [-f|--force] (--all|[--] <path>…​)
    git submodule [--quiet] update [<options>] [--] [<path>…​]
    git submodule [--quiet] summary [<options>] [--] [<path>…​]
    git submodule [--quiet] foreach [--recursive] <command>
    git submodule [--quiet] sync [--recursive] [--] [<path>…​]
    git submodule [--quiet] absorbgitdirs [--] [<path>…​]
    ————————————————
    版权声明:本文为CSDN博主「KongyunWu」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/wkyseo/article/details/81589477
    

    参考

    1. Git_liaoxuefeng
      MultiUser
    2. Git module

发表评论

您的电子邮箱地址不会被公开。