Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2114517
  • 博文数量: 374
  • 博客积分: 7276
  • 博客等级: 少将
  • 技术积分: 5668
  • 用 户 组: 普通用户
  • 注册时间: 2011-10-06 16:35
文章分类

全部博文(374)

文章存档

2013年(23)

2012年(153)

2011年(198)

分类: LINUX

2013-02-05 17:34:13

原文地址:补充一些git使用说明 作者:MagicBoy2010

这篇文章是早先在另一个论坛上写的,那个论坛估计要关闭了。把它移过来,因为我自己还要用: (reference to http://www.cnblogs.com/linuxkern ... /03/27/1997001.html)

1. install git
(you maybe need to config the git for all the repositories as:
# git config --global user.name "Name Your"
# git config --global user.email "name.your@gmail.com"

2. get kernel source code with git, for example,
   cd /home/dennis/Linux
   git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git linux-git
   A linux-git folder will be created in /home/dennis/Linux/linux-git automatically and all source codes will be downloaded there.
3. if the remote git repository has some update, ie, kernel version changes from 3.2.9 to 3.2.10, then uses: "git pull" command 
    to download all changes to your local copy.
4. "git branch" will show the current branch that you're working on.
5. You need to create a new branch on which you will work for codes changes, ie, "git branch s390vmurFix" then use "git  
   checkout s390vmurFix" switch the default('master') branch to your current branch 's390vmurFix'
   the command output looks like this:
   root@LinuxFGL:/home/dennis/Linux/linux-git# git checkout s390vmurFix
   Switched to branch 's390vmurFix'
   root@LinuxFGL:/home/dennis/Linux/linux-git# git branch
   master
   * s390vmurFix
   The '*' prefix of s390vmurFix means now the current branch is 's390vmurFix'
   use 'git branch -D s390vmurFix' command to delete this branch if you don't need it.
   use 'git add newfile.c' to add a new file 'newfile.c' into your current branch.
6. Now change the codes and save it. Launch the "git commit -a" after that, this command will open a text editor, you need to 
    input your commit log message there. Be careful what you input in the log message because these messages will become part
    of Linux Git tree commit log and people will be searching your commit based on these messages.(the text editor is not easy to  
    use, see if we can replace it with others, ie, vim) -- in some project, we can skip this step if no commit msg is necessary...
7. generate your patch with "git format-patch -s -n master.. s390vmurFix", after that you will get a patch like '0001-s390-Fix-a-
   memory-leak-issue-in-vmur-driver.patch'. OR, you can use bellow command to generate the patch email content in case .patch is not mandatory:
   #git diff --stat  // used to generate statistic data for your change
   #git diff  //used to generate the difference between the change above and the original source code branch
   
Please note all your changes is based on current branch, it's 's390vmurFix', so if you want to test your patch to see if it works, you need to switch your branch to 'master', like this "git checkout master", now the current branch will be 'master', you can verify that your changes made in step 6 will not show in the 'master' branch, so apply the patch to it:
root@LinuxFGL:/home/dennis/Linux/linux-git# patch -p1 < 0001-s390-Fix-a-memory-leak-issue-in-vmur-driver.patch
patching file drivers/s390/char/vmur.c

then check if the vmur.c in the 'master' branch has been updated by the above patch process.
If you want to roll back to the initial state (in other word, remove the patch just applied) in 'master' branch, just use:

"root@LinuxFGL:/home/dennis/Linux/linux-git# patch -p1 < 0001-s390-Fix-a-memory-leak-issue-in-vmur-driver.patch" again!

============================================================
Below red section is updated on Aug.24, 2014.

refer to: 
http://www.cnblogs.com/y041039/articles/2411600.html
The steps to use 'git format-patch' command instead of 'git diff':
#git branch patch-test
#git checkout patch-test
#'edit you code and save it'
#git commit -a -m "the message will follow the Subject in the patch email"
#git format-patch -M master -s // this patch will be generated by comparing with 'master' branch, '-s' flag will generate 'Signed-off-by' section.
Now you will get a patch looks like '0001-the message will follow the Subject in the patch email.patch' in your current working directory if everything is OK ;-) I hope so.
The changed code will be saved only on the 'patch-test' branch, your changes will not be there if you switch to the 'master' branch.

Now let's see how to apply the patch we just generated, we create a new branch named 'patch-apply' order to protect the 'master' not be tainted:
#git branch patch-apply
#git checkout patch-apply
#git am --signoff < 0001-the message will follow the Subject in the patch email.patch
Applying the message will follow the Subject in the patch email
// Sometimes you may encounter the error message like: rebase-apply still exists but mbox given. try to resolve it with 'git rebase --abort' command
// Now you need to commit this patch to make your change effective, something like the svn check-in...

#git commit -a -m "the test patch applied"
// You can use 'git log' to see the commit log for current branch you're working on
#git log  // You will find the test patch applied just now in the output of this command
commit f473ee7fc79fddd51352b9af71ef2c6934dad32e
Author: Dennis Chen
Date:   Mon Aug 25 16:58:06 2014 +0800


    commit message
    
    Signed-off-by: Dennis Chen


============================================================



root@:/Linux/linux-git# git pull
Updating c7b2855..c16fa4f
error: Your local changes to the following files would be overwritten by merge:
        Makefile
Please, commit your changes or stash them before you can merge.
Aborting
================================================
root@:/Linux/linux-git# git reset --hard HEAD
HEAD is now at c7b2855 aio: fix the "too late munmap()" race
root@:/Linux/linux-git# git pull
Updating c7b2855..c16fa4f

================================================
/>

git 删除错误提交的commit

2011-12-12 16:23:29


阅读(4459) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~