Git Learner Record

目录

What is a git

 git 帮助我们进行代码的版本控制,我于2015/10/1花费一天时间学习一个关于git的视频,然后再参考几篇博客,将git的使用方法全部弄清楚。let's begin!

Preparation

History

  1. SCCS Source Code Control System
    • 1972, closed source, free with Unix
  2. RCS Revision Control System
    • 1982, open source.
  3. CVS Concurrent Versions System
    • 1986 - 1990, open source
  4. SVN
    • 2000, open source
  5. BitKeeper SCM
    • distributed version
  6. GIT
    • github come out

Install

参考官网的安装方法 —— [git web]

  1. download the tar.gz or some package[your linux]
  2. tar zxvf *.tar.gz
  3. /configure
  4. make && make install
  5. finish.
    or you can try:
    • apt-get install git
    • yum install -y git
    • pacman -S git

configuration

  1. git config –global user.name [your name]
  2. git config –global user.email [your email]
  3. git config –global core.editor “vim”
  4. git config –global color.ui true
  5. use bash config
  6. help

Begin

init the git

  1. mkdir dir1
  2. cd dir1
  3. git init
  4. add one file (make change)
  5. git add . (add change)
  6. git commit -m “some word” (commit change)
  7. git log -n/ –since/ –until/ –grep

stream

working -add file- staging index -commit- repositiry

File Operations

Add (git status to check)

  • git add .
  • git commit -m “”
  • git diff
  • git commit -ma “”

Remove(git status to check)

  • git rm filename
  • git commit -m “”

Rename(git status to check)

  • git add file
  • git rm file
  • git commit -m “”
  • or you can use git mv file1 file2

Rollback

git diff to check to change


  1. git checkout – file(before add)
    it can return the status of the workspace.
  2. git reset HEAD file (after add)
    • unstage the file -> before add
    • git checkout – file
  3. git (after commit)
    • find the Hash value of commit
    • git comment –amend append to the same commit
    • git diff –staged
    • return the commit status

git checkout [commit hash] – file

Warning [git reset]

  1. –soft not change staging index & workspace
  2. –mixed(default) change staging & not workspace
  3. –hard change staging & change workspace
    usage : git reset –soft [commit hash]
    git reset HEAD file
    -n try to do -f force to do

.gitignore

it can help us to ignore some file or dir

reference :
1. help.github.com/articles/ignoring-files
2. github.com/github/gitignore
git config –global core.excludesfile pathtofile
* git rm –cached file

.gitkeep

git log –oneline/ –graph/ –all/ –decorate

Other options

  • git show [hash]
  • git diff [hash] & git diff [hash1]..[hash2]

Branch

branch is needed, cheap, try

  1. try new ideas
  2. isolate the workspace
  3. fast context switching

operations

  • git branch
  • create -> git branch new_branch_name
  • switch -> git checkout branch_name
  • git checkout -b new_branch_name
  • git diff [branch1]..[branch2] (use –color-words)
  • git branch –merged
  • git branch -m old_name new_name (–move)
  • git barnch -d(–delete) name (-D to delete a non-empty branch)
  • prompt
    1. export PS1=’$(__git_ps1 “(%s)”) > ‘
    2. export PS1=’\W$(__git_ps1 “(%s)”) > ‘
    3. export PS1=$PS1’$(__git_ps1 “(%s)”) > ’ (it’s cool !)

Attantion: barnch is a stack mode, current branch can’t be delete

Merge

  • git merge exist_branch
  • git branch –merged
  • conflict
      1. change by yourselt
      1. git log –graph –oneline –all –decorate
      1. git mergetool –tool=

Attention:
* keep lines short
* commits small focused
* merge often

stash

  1. git stash save “changed mission …”
  2. git stash list
  3. git stash show stash@{0} (you may use -p option)
  4. git stash apply
  5. git stash pop
  6. git stash drop stash@{0}

Remote Git
Easily, this can be changed to
Remote Git now

Set up a github account

  1. you set up a account
  2. Create a repository
  3. look at the code following
echo #  >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/[User account]/[project name].git
git push -u origin master


  • you can easy use
    git remote rm origin
  • git branch -a/-r
  • git push -f
  • git fetch
    • fetch before work
    • fetch before push
    • fetch often
  • git pull = git fetch + git merge
  • git push origin :your branch
  • git push origin [–delete] branch

[远程分支的使用]
git checkout -b [new_branch]
(make some change)
git commit -am “word”
git push [远程仓库名] [远程分支名(new_branch)]

password caching

Password Caching
or save the ssh key.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值