Showing posts with label Git. Show all posts
Showing posts with label Git. Show all posts

Friday, June 21, 2013

Changing GIT commit message from commit in history

$ git log
$ git rebase --interactive SHA_for_parent

Your editor will come up with several lines as seen in the image.
Change the word pick into reword in front of the commit you'd like to change.
A new file opens and you can edit the commit message.

$ git push --force
p.s.
to fix "Interactive rebase already started"
$ git rebase -i --abort
Read more ...

Git config

This post is from here.


git的全局配置,存储于$HOME/.gitconfig里,这里的配置影响当前用户的所有git repo

命令行里,通过git config--global参数开启全局配置
$: git config --global user.name yyfrankyy
$: git config --global user.email yyfrankyy@gmail.com

默认编辑器

$: git config --global core.editor vim

默认merge/diff 工具

注意设置后需要通过difftoolmergetool来启动
$: git config --global diff.tool vimdiff
$: git config --global difftool.prompt false
$: git difftool file.js

通过Alias 设置别名

一些常用的命令,可以通过设置别名来减少输入
分支切换是比较频繁的操作
$: git config --global alias.br branch
$: git br
* master
  prepub
日志也是经常需要看的
$: git config --global alias.last log --pretty=oneline -1 HEAD
$: git last
eba0f64370036ca57aa50b9938a3e70755f74aaa 我只是提交一下看看log..
以及上面提到的difftool
$: git config --global alias.df difftool

repo 级别的配置

repo级别的配置,存储在仓库目录的.git/config文件中这里的所有配置项跟全局一致,可以覆盖全局信息
比如公司项目,指定花名和公司邮箱:
$: git config user.name wenhe
$: git config user.email wenhe@taobao.com
git本身也会用于存储该库的远程仓库,分支列表等信息
$: cat .git/config
[core]
 repositoryformatversion = 0
 filemode = true
 bare = false
 logallrefupdates = true
[remote "s"]
 url = git@search.ued.taobao.net:projects/search.git
 fetch = +refs/heads/*:refs/remotes/s/*
[branch "master"]
 remote = s
 merge = refs/heads/master
[branch "prepub"]
 remote = s
 merge = refs/heads/prepub
[branch "product"]
 remote = s
 merge = refs/heads/product

我的全局配置[2010-10-22 ]

$: cat ~/.gitconfig
[user]
 name = yyfrankyy
 email = yyfrankyy@gmail.com
[core]
 excludesfile = /home/wenhe/.gitignore
 quotepath = false
 editor = vim
[alias]
 co = checkout
 ci = commit
 br = branch
 st = status
 unstage = reset HEAD --
 last = log -1 HEAD
 mg = merge
 glog = log --pretty=oneline --graph
 df = difftool
[color]
 ui = true
[format]
 pretty = oneline
[diff]
 tool = gvimdiff
[difftool]
 prompt = false
[merge]
 tool = gvimdiff
最新的gitconfig文件,可以到 这里 查看

References 

Read more ...

How to remove file and commit from history

This post is from here.


假设我们的 commit tree 如下:
R-A-B-C-D-E-HEAD

接下来要移除 B 和 C 的 commit tree, 变成,
R-A-D'-E-HEAD

有两种方式可以移除 B & C
# detach head and move to D commit 
git checkout   < SHA1-for-D > 
# move HEAD to A, but leave the index and working tree as for D 
git reset   --soft   < SHA1-for-A > 
# Redo the D commit re-using the commit message, but now on top of A 
git commit   -C   < SHA1-for-D > 
# Re-apply everything from the old D onwards onto this new place  
git rebase   --onto  HEAD  < SHA1-for-D >  master 
# push it

git push   --force

另一种方法是利用 cherry-pick 方式
git rebase   --hard   < SHA1 of A > 
git cherry-pick   < SHA1 of D > 
git cherry-pick   < SHA1 of E > 

這會直接忽略 B 跟 C 的 history,詳細資料可以查詢 git help cherry-pick 或者是 git help rebase 

Read more ...