git (code school 笔记)

包括git real,git real2,master github 三个课程的笔记
// code school 已被plural sight 收购。。。现在这些课程需要用code school 做关键字搜索才能找到
// https://www.pluralsight.com/codeschool
比较混乱。。。。

0.config
git config --global user.name ‘yourname’
git config --global user.email ‘[email protected]
git config --global color.ui true
git config --global core.editor emacs
git config --global merge.tool opendiff
git config user.email ‘[email protected]’ # for current repo
git config --list
git config user.email

alias:
git config --global alias.mylog "log --pretty=format: ‘%h %s [%an] --graph’
git mylog

git log --pretty=oneline
git log --pretty=format:"%h"#只输出sha哈希值,具体用到的时候在查吧。。。
git long --oneline
git log --oneline -p #具体的修改
git log --oneline --stat #修改的行数
git log --oneline --graph #timeline的图
git log --until=1.minute.ago
git log --since=1.day.ago
git log --since=1.hour.ago
git log --since=1.month.ago --until=2.weeks.ago
git log --since=2000-01-01 --until=2012-12-21

git blame filename --date short

.git/info/exclude #用来处理个人的例外
文件中的条目例子:
xxx.txt
.txt
folder/
folder/
.txt

.gitigonre #用来处理一些所有人的例外
logs/*.log

git rm xxx.txt #untrack 同时删除文件
git rm --cached xxx.txt # 文件变为untrack,stage中会有delete, 但是不从文件系统删除

git diff #staged current
git diff staged #HEAD staged
git diff HEAD #HEAD current
git diff commit_id_old commit_id_new
git diff HEAD^
git diff HEAD^^
git diff HEAD~5
git diff HEAD^…HEAD
git diff branch1 branch2
git diff --since=1.week.ago --until=1.minute.ago

git add --all #所有修改过的和没track的
git add .txt #当前目录下txt
git add "
.txt" #所有目录下txt(包括子目录)

git reset # stage -> edit
git reset commit_id # commits after commit_id -> edit

git reset --soft HEAD^ #last commit -> stage
git reset --hard + git clean -f # 清除track的文件的改动+清除untrack的文件

git push -u origin master #master是指本地的分支
git push -u origin local_branch:remote_branch
git push origin :delete_branch # 删除远程分支

git pull
= git fetch + git merge

git check -b new_branch
= git branch new_branch + git checkout new_branch

如果 合并的一个分支并没有改动fastforward
如果两个分支上都有改动recursive

git fetch #获得远程库信息
git branch -r #远程分支
git branch -a #所有分支

git push origin --delete branch_name
git remote show origin
git remote prun origin

git tag
git checkout v0.0.1
git tag -a v0.0.1 -m ‘versionxxx’
git push --tags

rebase和merge
1.merge
git checkout master
git merge work_branch #conflict may happen, maybe recursive merge, if recursive, there will be a merge commit

2.rebase
git checkout work_branch
git rebase master #conflict may happen, solve conflict->add file -> rebase continue
git checkout master
git merge work_branch #fast forward no merge commit

git rebase -i #神器

3.stash
git stash = git stash save
git pop = git stash apply + git stash drop

git stash save --keep-index #只stash unstaged 的文件
git stash save --include-untracked #stash untracked的文件

git stash list
git stash list --stat
git stash show = git stash show stash@{0}
git stash show --patch

git stash save “message”
git stash branch newbranch stash@{0}

git stash clear

4.history
git clone cur_dir new_dir
git filter-branch --tree-filter ‘rm -f xxx.txt’ – --all
git filter-branch -f --tree-filter ‘rm -f xxx.txt’ – --all
git filter-branch --tree-filter ‘rm -f xxx.txt’ – HEAD
git filter-branch --tree-filter ‘find . -name “.txt” -exec rm {} ;’

git filter-branch --index-filter ‘git rm --cached --ignore-unmatch xxx.txt’ – --all

git filter-branch -f --prune-empty – --all
git filter-branch --tree-filter ‘rm -f xxx.txt’ --prune-empty – --all

5.回车
git config --global core.autocrlf input
git config --global core.autocrlf true
git config --global core.autocrlf false

6.cherry-pick
git cherry-pick --no-commit hash1 hash2
git cherry-pick --eidt hash
git cherry-pick -x
git cherry-pick --signoff

7.submodule
git clone + git submodule init + git submodule update
git push --recurse-submodules=check
git push --recurse-submodules=on-demand
git config alias.pushall “push --recurse-submodules=on-demand”

8.log
git reflog
git log --walk-reflogs

9.other config
git config --global push.default sim

git pull --rebase = git fetch + git rebase
git config --global pull.rebase true

git congif --global rerere.enable true

git status -s

  1. git merge --no-ff feacher_branch #强制recursisve merge

11.tag
git tag -a v1.1.1 -m “”
git push --tags

12.github api
token 使用
$ curl -i -H’Authorization: token ****************************************’ htt
ps://api.github.com/user
数据例子:
$ curl -i -H’Authorization: token ****************************************’ -d’
{“name”:“api_test”}’ https://api.github.com/user/repos

你可能感兴趣的:(git)