Monday, April 4, 2016

Git Braindump

View 
tree .git cat .git/HEAD cat .git/refs/heads/master git reflog git checkout -b topic git reset --head git reset --head [SHA] //point to ci git checkout master grh [SHA] gl master topic gbrt //all branch in time order  git log ..[branchname] //msg, not including head git status --short git add --update // staging grep -r'<<<<' // conflicts gl HEAD@{1} alias gm="git merge --no--ff" gmf="merge --ff--only" //no fast forward
Merge == new commit, no chg hist, Rebase = recommit a set of ci on top of new point, new hist
git rebase --abort gp origin local:remote git push :[branchname] //delete remote branch git log --patch filename git log -S'key word' // search entire commit  git log --patch -S"" //patch format git log --all --simplify-by-decoration //only tagged, branched git l --simplify-by-decoration git clean -n // untracked ignored -n= safe dry run rvm use default@global gem install git-smart git smart-pull 

Between Remote and Local
msysgit windows install, tortoisegit --mimic svn gitextensioin instead.(window explorer integration)
git init //create repo c:\prog x86\Git\etc\gitconfig  c:\Users\w3333\.gitconfig git config
git remote rm origin git remote -v git remote add origin git@github.com:jqd/myproj.git
git clone http://.../proj.git git log --oneline --graph |wc -l git shortlog -sne git show HEAD~10 git remote -v //verbose show fetch/push url  protocols http/git/ssh/file cat .git/config

git branch [-r] //remote gita tag git remote -v git remote add origin http://../jqd/proj1.git=>git fetch //pull down git fetch origin //where  git log origin/master //chg in remote but not in head git log //not integrated into local yet git merge origin/master //now local will have  remote chg and git log will show ff
git pull=git fetch;git merge origin/mster
git branch --set-upstream orgin/master // remote tracking branch git pull git clone set upstream automatically
git status git commit -am 'msg' git push  //ask uid/pwd for http
git remote add origin git@github.com.jqd.proj1.git //use SSH version url no more uid/pwd ssh key git tag v1.0 git tag git tag -a "msg" v1.0 git push --tags //tag must be pushed

Working locally
git init git status git add f2.txt
git commit // brings up vim/notepad, git commit -a "msg" //avoid editor  git add -u // stage not add file not the same as git add -A //truly add, no more untracked
git add f1.txt //stage not add,  rm f2.txt=> git add -u =>git commit //del=>stage=>ci del
git diff dd6819..a15ec6 //only need 6 in SHA git diff HEAD~1..HEAD = git diff HEAD~1 //back 1

git checkout f1.txt //override changes git reset --hard HEAD //back to HEAD throw away local git reset --hard HEAD~1 //set head back git reset --soft HEAD~1 //move changes back to working/loc copy, head no changes
git clean -n //dry run clean up working dir git clean -f //force

vim .gitignore /logs /logs/*.txt git add .gitignore git commit -a "add ig" .gitignore.

Branch/Merge/Rebase
git log --oneline --graph --all --decorate //show head,tag,branch,master git config
git config --global alias.gla "log --graph --oneline --all --decorate" git lga //git log all cat ~/.gitconfig
git branch feature1 git checkout feature1 = git checkout -b feature1 //branch and switch locally.

git lga=> make changes=>gig commit -am "msg" =>git lga=>4577ae [HEAD,feature1 //head feature both point to changes

git checkout master=>2332dc6 [HEAD naster] //head point away

git branch fix1 974b5a=>git checkout fix1=>changes=>git commit -am""=>git lga [HEAD fix1] // shows a new [5a78cb7 HEAD] above everyone including master
git branch -m fix bug123 // move=rename git branch -d bug123 //cannot del since change not merged to master
git branch -D bug123 // force del=D
git reflot =>git branch bug123 5a78cb => git checkout bug123 //un-delete if<30days

git checkout f3 =>make changes=>git stash=>git stash list=>(switch away fix bug123)=> git check f3=>git stash apply // come back to f3 work
git reset --hard HEAD => git stash apply //still restore from stash git stash pop =apply but loss on hard-reset git stash drop git stash branch f3_addl
git checkout masgter=>git merge f1  //ff master to f1 [f1,master,HEAD] git branch -d f1 [master,HEAD]
git mergetool //beyoundcompare kdiff3 git diff --cached //repo vs. staging git commit -m "merg into master"
git branch f3 v1.0 // branch from [tag,master]=>[HEAD,f3] git show f3
git checkout f3=> changes=> git commit -am => git rebase master=>git lga //f3 not longer from [tag,master] rather it is on top of master 
git checkout master => git merge f3 //ff merf just move [master HEAD,f3]
git rebase master=>conflict tools=>rm *.orig =>git diff --cahsed=>git rebase --continue Rebase = replay commit on top of mast but rebase is dangerous 

Cherry Picking
git checkout master //have two commits but only want 1 in master, cannot rebase or merge 
git cherry-pick 6fa4327 => git lga 19ae38f7 [HEAD,master] "fix from 6fa4327"



git fetch origin master  git push = git push origin master // ff [master origin/master HEAD]
git push origin v1.0_fix  //new remote branch created git branch -r  // show orign/master origin/v1.0__fix 
git push origina v1.0_fix:v10_remote_name // give it a name
(strange way to delete remote branch by local name=null) git push origin :v10_remote_anme
git rebase -i HEAD~3 //modify last 3 commit message may need git rebase --continue/abort. git log --graph --oneline to check git reset --hard 7e458f9 // delete commit from local
git log --cc --since="6am" --author="joe" | git diff-tree -v

start git repo
(1) There are no git command to create Repo.
(2) General structure  Project/Repos  e.g. eTrading/ET-Options, ET-RFQ, ET-Equity
    for personal git, there are no project ( or default just one for your own repo)
      https://stash-prod1.us.myFirm.net:8443/projects/eTrading
      https://stash-prod1.us.myFirm.net:8443/users/w123
(3) git clone empty repo would get local repo established but no origin
   git clone https://stash-prod1.us.myFirm.net:8443/projects/eTrading/ET-Options.git
   git clone https://W123@stash-prod1.us.myFirm.net:8443/scm/~w123/e-trading.git
(4) init-commit local-add origin-push master--connecting to git
    (There are no develop yet)
cd existing-project
git init
git add --all
git commit -m "Initial Commit"
git remote add origin https://W123@stash-prod1.us.myFirm.net:8443/scm/~w123/e-trading.git
git push origin master

(5) switch code tracking on git
cd existing-project
git remote set-url origin https://W123@stash-prod1.us.myFirm.net:8443/scm/~w123/e-trading.git
git push origin master

submodule --- point to a specific commit of other repo, not tracking
git clone url_superProj => subm_dir empty git submodule update --init // bring down a subm commit
cat .gitmodules shows url dir of subm inside superproject
git submodule add url path_subm git status git log git push origin master:master brnch:brnch // all for separate commit of subm. must fork if no perm for subm.
git add subm_name // upd to new commit in the subm, not automatically bring down
cd subm_dir git push origin master:master // must push separately and 1st
git reset HEAD subm_name // remove changes or branching git push origin b1:b1 // new remote branching.
git submodule update 

No comments:

Post a Comment