[程式] Git
- Remove all temporary files (unstaged) with Git
$ git add .
$ git rm -f *~
- Edit commit message
Case - The most recent one
$ git commit --amend
Case - Not the most recent one
a. $ git rebase -i
b. In editor, modify the "pick" to "edit" in the front of the commit you want to edit => save & quit
c. $ git commit --amend
Editor should be opened automatically to let user edit commit message => save & quit
d. $ git rebase --continue
REF: http://blog.yorkxin.org/posts/2011/07/29/git-rebase
- Combine multiple commits into one
a. $ git rebase -i HEAD~2 // Combine latest 2 commits
b. In editor, modify all "pick" to "squash" except the first one
(the commented lines should be also ignored)
c. After save & quit, editor should be opened automatically to let user combine commit message
REF:
https://ariejan.net/2011/07/05/git-squash-your-latests-commits-into-one/
http://zerodie.github.io/blog/2012/01/19/git-rebase-i/
- Multiple branches in one branch folder
$ git branch -a // check all local and remote branches
$ git checkout -b <new branch name> -t <remote branch name (texts after "remotes/")>
- Cherry-pick change to different branch which is on the same server
$ git log <other branch name> // check commit id on the original branch
$ git cherry-pick <commit id>
- Reset
To reset to specific commit
$ git reset --hard <commit id>
or
To reset to resent ? commits
$ git reset --hard HEAD~?
- Update status of remote branches
$ git remote update
- Error - unable to upload due to no new changes
[E]
! [remote rejected] HEAD -> <branch name> (no new changes)
[S]
Modiyfy Chage-Id in commit message with "git commit --amend"
- Track remote branch
New branch, git checkout -b <new branch name> -t <remote branch name (texts after "remotes/")>
Existing branch, git branch -u <remote branch name (texts after "remotes/")>
- Checkout all
repo_asus forall -c "git checkout <branch name>"
Warning - refname 'HEAD' is ambiguous
[W]
warning: refname 'HEAD' is ambiguous.
[S]
git config --global core.warnambiguousrefs false
- Rename branch name
CASE - not on the branch to rename
$ git branch -m <old branch name> <new branch name>
CASE - already on the branch to rename
$ git branch -m <new branch name>
REF: http://fredchiu.wordpress.com/2011/12/28/%E9%87%8D%E6%96%B0%E5%91%BD%E5%90%8D-rename-git-branch/
- Commit specific commit only
git push <remote name> <commit id>:<remote branch name>
ie. Replace HEAD with <commit id>
- Log between tags
$ git log tagA...tagB
add "--pretty=oneline" to show title only
$ git log tagA...tagB --pretty=oneline
- Auto Change-Id generation
if there is no Change-Id generated after commit, try the following command
$ scp -p -P 29418 <username>@<ip>:hooks/commit-msg .git/hooks/
沒有留言:
張貼留言