User Tools

Site Tools


work:git-guide

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
work:git-guide [2013/04/27 21:41] – [git checkout remote branch] percywork:git-guide [2018/02/05 19:15] (current) – [git checkout specified file from another branch] percy
Line 363: Line 363:
 ==== git checkout remote branch ==== ==== git checkout remote branch ====
 Check the remote branch list Check the remote branch list
-  git branch -r+  git branch -rv
 Then create a local branch from the remote branch Then create a local branch from the remote branch
   git checkout -b test origin/test   git checkout -b test origin/test
 +  
 +Commit to a remote branch:
 +  git push origin proguard
      
 Reference:http://stackoverflow.com/questions/1783405/git-checkout-remote-branch Reference:http://stackoverflow.com/questions/1783405/git-checkout-remote-branch
      
 +==== git add local to the remote  ====
 +<code>
 +git init
 +git remote add origin https://github.com/pjq/SoundRecordingExample2.git
 +git status
 +git pull
 +git pull origin master
 +git status
 +git add .
 +git commit -m "init commit"
 +git push origin master
 +</code>
 +
 +==== change url ====
 +  git remote set-url origin https://github.com/jikabao/merchantapp_android.git
 +
 +==== create patch ====
 +
 +  git show 3514997d38509ab5492e32afc3e4e872daf7932e >DashboardGLPLTitle.patch
 +  patch -p1  <DashboardGLPLTitle.patch
 +  
 +Or you can create patch between two commitid
 +  git diff old-commitid new-commitid >diff.patch
 +  git diff 557393295b0811278de4875d5fc5558988371bca 0abea5c74c10b81672817aa93ae21cc4852b7702 >diff.patch
 +  
 +If you want to revert your patch -R
 +  patch -R -p1 <../diff.patch
 +  
 + 
 +==== git auto-complete ====
 +
 +http://blog.jameschevalier.us/how-to-add-auto-completion-to-git/
 +
 +  wget https://raw.github.com/git/git/master/contrib/completion/git-completion.bash -O ~/.git-completion
 +  sudo vim /etc/bashrc
 +  source /Users/pengjianqing/.git-completion
 +  
 +==== git alias ====
 +  
 +http://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks
 +  
 +<code BASH>
 +git config --global alias.co checkout
 +git config --global alias.br branch
 +git config --global alias.ci commit
 +git config --global alias.st status
 +git config --global alias.visual '!gitk'
 +</code>
 +
 +==== git tag ====
 +
 +<code>
 +   git tag release/1.2.9
 +   git tag -l
 +   git push origin tag release/1.2.9
 +  </code>
 +
 +==== git checkout tag ====
 +First make sure that the tag exists locally by doing
 +
 +  git fetch --tags
 +Then check out the tag by running
 +  git checkout tags/<tag_name>
 +  
 +Then create new branch base on the current commitment
 +  git branch newtagbranch
 +  
 +==== git fetch & git merge ====
 +
 +Refer to
 +  - http://www.ruanyifeng.com/blog/2014/06/git_remote.html
 +  - http://www.cnblogs.com/youxin/p/3470335.html
 +  - http://longair.net/blog/2009/04/16/git-fetch-and-merge/
 +
 +<code>
 +git checkout feature/sp_xd
 +git fetch origin feature/sp_xd:tmp
 +git diff tmp
 +git merge tmp
 +
 +git checkout feature/sp_xd
 +git fetch --all
 +git fetch origin feature/sp_xd
 +git diff feature/sp_xd origin/feature/sp_xd
 +git merge origin/feature/sp_xd
 +
 +git branch -D tmp
 +
 +git checkout feature/sp_xd
 +git fetch origin feature/sp_xd
 +git checkout -b newBrach origin/feature/sp_xd
 +
 +#Delete the local branch that already deleted from the remote
 +git remote prune origin
 +
 +#Remote server
 +git remote -v
 +
 +#Remote branch
 +git branch -r
 +#All branch
 +git branch -a
 +
 +#Show the remote repo information
 +git remote show origin
 +git remote prune origin
 +</code>
 +
 +==== git subtree ====
 +Refer to
 +http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/
 +<code bash>
 +git remote add -f datalayer   https://Jianqing.Peng@stash.englishtown.com/scm/mobile/datalayer-android.git 
 +git subtree add  --prefix=datalayer datalayer integration_lean --squash
 +git fetch all  --prune   
 +git fetch datalayer integration_lean
 +git subtree pull --prefix=datalayer/ datalayer integration_lean --squash
 +git subtree push --prefix=datalayer/ datalayer integration_lean
 +</code>
 +
 +
 +==== git checkout specified file from another branch ====
 +
 +  * http://stackoverflow.com/questions/2364147/how-to-get-just-one-file-from-another-branch
 +
 +  git checkout branch_name -- path/to/file
 +  
 +==== git revert ====
 +
 +github support revert the pull request, so after you have revert the pull request, and still want to merge the feature branch, then you need to find the revert commit id, and revert it again
 +
 +  git revert ce8731f5cbc55ab50723ee2a8ec615b462b3b0e6 -m 1
 +
 +So the full log will be like
 +<code>
 +commit 817947e37c5f835384fd282ab2004a6d9a848975 (HEAD -> pjq/testing, origin/pjq/testing)
 +Author: Jianqing Peng <Jianqing.Peng@sap.com>
 +Date:   Mon Feb 5 19:09:40 2018 +0800
 +
 +    Revert "Merge pull request #2087 from sfofficial/revert-2086-pjq/testing_new_feature"
 +    
 +    This reverts commit ce8731f5cbc55ab50723ee2a8ec615b462b3b0e6, reversing
 +    changes made to 67a513f686ec9c203b7d38a3df1abbe7079320d4.
 +
 +commit ce8731f5cbc55ab50723ee2a8ec615b462b3b0e6
 +Merge: 67a513f686 a157cdef4e
 +Author: Jianqing Peng <jianqing.peng@sap.com>
 +Date:   Mon Feb 5 19:07:33 2018 +0800
 +
 +    Merge pull request #2087 from sfofficial/revert-2086-pjq/testing_new_feature
 +    
 +    Revert "add new feature 1"
 +
 +commit a157cdef4e391981b2053b52f560a70464b2dd7f
 +Author: Jianqing Peng <jianqing.peng@sap.com>
 +Date:   Mon Feb 5 19:06:29 2018 +0800
 +
 +    Revert "add new feature 1"
 +
 +commit 67a513f686ec9c203b7d38a3df1abbe7079320d4
 +Merge: 08a5c9c33e a161eed1e3
 +Author: Jianqing Peng <jianqing.peng@sap.com>
 +Date:   Mon Feb 5 19:05:57 2018 +0800
 +
 +    Merge pull request #2086 from sfofficial/pjq/testing_new_feature
 +    
 +    add new feature 1
 +
 +commit a161eed1e3d200f6121690494dd6df1d065163fb (origin/pjq/testing_new_feature, pjq/testing_new_feature)
 +Author: Jianqing Peng <Jianqing.Peng@sap.com>
 +Date:   Mon Feb 5 19:05:11 2018 +0800
 +
 +    add new feature 1
 +
  
 +</code>
/var/www/dokuwiki/wiki/data/attic/work/git-guide.1367070114.txt.gz · Last modified: 2016/05/05 13:06 (external edit)