6 个方便的 Git 脚本 | Linux 中国

Posted Linux中国

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了6 个方便的 Git 脚本 | Linux 中国相关的知识,希望对你有一定的参考价值。

当使用 Git 存储库时,这六个 Bash 脚本将使你的生活更轻松。
-- Bob Peterson

我编写了许多 Bash 脚本,这些脚本使我在使用 Git 存储库时工作更加轻松。我的许多同事说没有必要:我所做的一切都可以用 Git 命令完成。虽然这可能是正确的,但我发现脚本远比尝试找出适当的 Git 命令来执行我想要的操作更加方便。

1、gitlog

gitlog 打印针对 master 分支的当前补丁的简短列表。它从最旧到最新打印它们,并显示作者和描述,其中 H 代表 HEAD^ 代表 HEAD^2 代表 HEAD~2,依此类推。例如:

  
    
    
  
  1. $ gitlog
  2. -----------------------[ recovery25 ]-----------------------
  3. (snip)
  4. 11 340d27a33895 Bob Peterson gfs2: drain the ail2 list after io errors
  5. 10 9b3c4e6efb10 Bob Peterson gfs2: clean up iopen glock mess in gfs2_create_inode
  6. 9 d2e8c22be39b Bob Peterson gfs2: Do proper error checking for go_sync family of glops
  7. 8 9563e31f8bfd Christoph Hellwig gfs2: use page_offset in gfs2_page_mkwrite
  8. 7 ebac7a38036c Christoph Hellwig gfs2: don't use buffer_heads in gfs2_allocate_page_backing
  9. 6 f703a3c27874 Andreas Gruenbacher gfs2: Improve mmap write vs. punch_hole consistency
  10. 5 a3e86d2ef30e Andreas Gruenbacher gfs2: Multi-block allocations in gfs2_page_mkwrite
  11. 4 da3c604755b0 Andreas Gruenbacher gfs2: Fix end-of-file handling in gfs2_page_mkwrite
  12. 3 4525c2f5b46f Bob Peterson Rafael Aquini's slab instrumentation
  13. 2 a06a5b7dea02 Bob Peterson GFS2: Add go_get_holdtime to gl_ops
  14. ^ 8ba93c796d5c Bob Peterson gfs2: introduce new function remaining_hold_time and use it in dq
  15. H e8b5ff851bb9 Bob Peterson gfs2: Allow rgrps to have a minimum hold time

如果我想查看其他分支上有哪些补丁,可以指定一个替代分支:

  
    
    
  
  1. $ gitlog recovery24

2、gitlog.id

gitlog.id 只是打印出补丁的 SHA1 ID:

  
    
    
  
  1. $ gitlog.id
  2. -----------------------[ recovery25 ]-----------------------
  3. 56908eeb6940 2ca4a6b628a1 fc64ad5d99fe 02031a00a251 f6f38da7dd18 d8546e8f0023 fc3cc1f98f6b 12c3e0cb3523 76cce178b134 6fc1dce3ab9c 1b681ab074ca 26fed8de719b 802ff51a5670 49f67a512d8c f04f20193bbb 5f6afe809d23 2030521dc70e dada79b3be94 9b19a1e08161 78a035041d3e f03da011cae2 0d2b2e068fcd 2449976aa133 57dfb5e12ccd 53abedfdcf72 6fbdda3474b3 49544a547188 187032f7a63c 6f75dae23d93 95fc2a261b00 ebfb14ded191 f653ee9e414a 0e2911cb8111 73968b76e2e3 8a3e4cb5e92c a5f2da803b5b 7c9ef68388ed 71ca19d0cba8 340d27a33895 9b3c4e6efb10 d2e8c22be39b 9563e31f8bfd ebac7a38036c f703a3c27874 a3e86d2ef30e da3c604755b0 4525c2f5b46f a06a5b7dea02 8ba93c796d5c e8b5ff851bb9

同样,它假定是当前分支,但是如果需要,我可以指定其他分支。

3、gitlog.id2

gitlog.id2 与 gitlog.id 相同,但顶部没有显示分支的行。这对于从一个分支挑选所有补丁到当前分支很方便:

  
    
    
  
  1. $ # 创建一个新分支
  2. $ git branch --track origin/master
  3. $ # 检出刚刚创建的新分支
  4. $ git checkout recovery26
  5. $ # 从旧的分支挑选所有补丁到新分支
  6. $ for i in `gitlog.id2 recovery25` ; do git cherry-pick $i ;done

4、gitlog.grep

gitlog.grep 会在该补丁集合中寻找一个字符串。例如,如果我发现一个错误并想修复引用了函数 inode_go_sync 的补丁,我可以简单地执行以下操作:

  
    
    
  
  1. $ gitlog.grep inode_go_sync
  2. -----------------------[ recovery25 - 50 patches ]-----------------------
  3. (snip)
  4. 11 340d27a33895 Bob Peterson gfs2: drain the ail2 list after io errors
  5. 10 9b3c4e6efb10 Bob Peterson gfs2: clean up iopen glock mess in gfs2_create_inode
  6. 9 d2e8c22be39b Bob Peterson gfs2: Do proper error checking for go_sync family of glops
  7. 152:-static void inode_go_sync(struct gfs2_glock *gl)
  8. 153:+static int inode_go_sync(struct gfs2_glock *gl)
  9. 163:@@ -296,6 +302,7 @@ static void inode_go_sync(struct gfs2_glock *gl)
  10. 8 9563e31f8bfd Christoph Hellwig gfs2: use page_offset in gfs2_page_mkwrite
  11. 7 ebac7a38036c Christoph Hellwig gfs2: don't use buffer_heads in gfs2_allocate_page_backing
  12. 6 f703a3c27874 Andreas Gruenbacher gfs2: Improve mmap write vs. punch_hole consistency
  13. 5 a3e86d2ef30e Andreas Gruenbacher gfs2: Multi-block allocations in gfs2_page_mkwrite
  14. 4 da3c604755b0 Andreas Gruenbacher gfs2: Fix end-of-file handling in gfs2_page_mkwrite
  15. 3 4525c2f5b46f Bob Peterson Rafael Aquini's slab instrumentation
  16. 2 a06a5b7dea02 Bob Peterson GFS2: Add go_get_holdtime to gl_ops
  17. ^ 8ba93c796d5c Bob Peterson gfs2: introduce new function remaining_hold_time and use it in dq
  18. H e8b5ff851bb9 Bob Peterson gfs2: Allow rgrps to have a minimum hold time

因此,现在我知道补丁 HEAD~9 是需要修复的补丁。我使用 git rebase -i HEAD~10 编辑补丁 9,git commit -a --amend,然后 git rebase --continue 以进行必要的调整。

5、gitbranchcmp3

gitbranchcmp3 使我可以将当前分支与另一个分支进行比较,因此我可以将较旧版本的补丁与我的较新版本进行比较,并快速查看已更改和未更改的内容。它生成一个比较脚本(使用了 KDE 工具 ,该工具也可在 GNOME3 上使用)以比较不太相同的补丁。如果除行号外没有其他差异,则打印 [SAME]。如果仅存在注释差异,则打印 [same](小写)。例如:

  
    
    
  
  1. $ gitbranchcmp3 recovery24
  2. Branch recovery24 has 47 patches
  3. Branch recovery25 has 50 patches
  4. (snip)
  5. 38 87eb6901607a 340d27a33895 [same] gfs2: drain the ail2 list after io errors
  6. 39 90fefb577a26 9b3c4e6efb10 [same] gfs2: clean up iopen glock mess in gfs2_create_inode
  7. 40 ba3ae06b8b0e d2e8c22be39b [same] gfs2: Do proper error checking for go_sync family of glops
  8. 41 2ab662294329 9563e31f8bfd [SAME] gfs2: use page_offset in gfs2_page_mkwrite
  9. 42 0adc6d817b7a ebac7a38036c [SAME] gfs2: don't use buffer_heads in gfs2_allocate_page_backing
  10. 43 55ef1f8d0be8 f703a3c27874 [SAME] gfs2: Improve mmap write vs. punch_hole consistency
  11. 44 de57c2f72570 a3e86d2ef30e [SAME] gfs2: Multi-block allocations in gfs2_page_mkwrite
  12. 45 7c5305fbd68a da3c604755b0 [SAME] gfs2: Fix end-of-file handling in gfs2_page_mkwrite
  13. 46 162524005151 4525c2f5b46f [SAME] Rafael Aquini's slab instrumentation
  14. 47 a06a5b7dea02 [ ] GFS2: Add go_get_holdtime to gl_ops
  15. 48 8ba93c796d5c [ ] gfs2: introduce new function remaining_hold_time and use it in dq
  16. 49 e8b5ff851bb9 [ ] gfs2: Allow rgrps to have a minimum hold time
  17. Missing from recovery25:
  18. The missing:
  19. Compare script generated at: /tmp/compare_mismatches.sh

6、gitlog.find

最后,我有一个 gitlog.find 脚本,可以帮助我识别补丁程序的上游版本在哪里以及每个补丁的当前状态。它通过匹配补丁说明来实现。它还会生成一个比较脚本(再次使用了 Kompare),以将当前补丁与上游对应补丁进行比较:

  
    
    
  
  1. $ gitlog.find
  2. -----------------------[ recovery25 - 50 patches ]-----------------------
  3. (snip)
  4. 11 340d27a33895 Bob Peterson gfs2: drain the ail2 list after io errors
  5. lo 5bcb9be74b2a Bob Peterson gfs2: drain the ail2 list after io errors
  6. 10 9b3c4e6efb10 Bob Peterson gfs2: clean up iopen glock mess in gfs2_create_inode
  7. fn 2c47c1be51fb Bob Peterson gfs2: clean up iopen glock mess in gfs2_create_inode
  8. 9 d2e8c22be39b Bob Peterson gfs2: Do proper error checking for go_sync family of glops
  9. lo feb7ea639472 Bob Peterson gfs2: Do proper error checking for go_sync family of glops
  10. 8 9563e31f8bfd Christoph Hellwig gfs2: use page_offset in gfs2_page_mkwrite
  11. ms f3915f83e84c Christoph Hellwig gfs2: use page_offset in gfs2_page_mkwrite
  12. 7 ebac7a38036c Christoph Hellwig gfs2: don't use buffer_heads in gfs2_allocate_page_backing
  13. ms 35af80aef99b Christoph Hellwig gfs2: don't use buffer_heads in gfs2_allocate_page_backing
  14. 6 f703a3c27874 Andreas Gruenbacher gfs2: Improve mmap write vs. punch_hole consistency
  15. fn 39c3a948ecf6 Andreas Gruenbacher gfs2: Improve mmap write vs. punch_hole consistency
  16. 5 a3e86d2ef30e Andreas Gruenbacher gfs2: Multi-block allocations in gfs2_page_mkwrite
  17. fn f53056c43063 Andreas Gruenbacher gfs2: Multi-block allocations in gfs2_page_mkwrite
  18. 4 da3c604755b0 Andreas Gruenbacher gfs2: Fix end-of-file handling in gfs2_page_mkwrite
  19. fn 184b4e60853d Andreas Gruenbacher gfs2: Fix end-of-file handling in gfs2_page_mkwrite
  20. 3 4525c2f5b46f Bob Peterson Rafael Aquini's slab instrumentation
  21. Not found upstream
  22. 2 a06a5b7dea02 Bob Peterson GFS2: Add go_get_holdtime to gl_ops
  23. Not found upstream
  24. ^ 8ba93c796d5c Bob Peterson gfs2: introduce new function remaining_hold_time and use it in dq
  25. Not found upstream
  26. H e8b5ff851bb9 Bob Peterson gfs2: Allow rgrps to have a minimum hold time
  27. Not found upstream
  28. Compare script generated: /tmp/compare_upstream.sh

补丁显示为两行,第一行是你当前的修补程序,然后是相应的上游补丁,以及 2 个字符的缩写,以指示其上游状态:

◈  lo 表示补丁仅在本地( local)上游 Git 存储库中(即尚未推送到上游)。
◈  ms 表示补丁位于 Linus Torvald 的主( master)分支中。
◈  fn 意味着补丁被推送到我的 “for-next” 开发分支,用于下一个上游合并窗口。   我的一些脚本根据我通常使用 Git 的方式做出假设。例如,当搜索上游补丁时,它使用我众所周知的 Git 树的位置。因此,你需要调整或改进它们以适合你的条件。 gitlog.find 脚本旨在仅定位   和   补丁,因此,除非你是 GFS2 开发人员,否则你需要针对你感兴趣的组件对其进行自定义。

源代码

以下是这些脚本的源代码。

1、gitlog

  
    
    
  
  1. #!/bin/bash
  2. branch=$1
  3. if test "x$branch" = x; then
  4. branch=`git branch -a | grep "*" | cut -d ' ' -f2`
  5. fi
  6. patches=0
  7. tracking=`git rev-parse --abbrev-ref --symbolic-full-name @{u}`
  8. LIST=`git log --reverse --abbrev-commit --pretty=oneline $tracking..$branch | cut -d ' ' -f1 |paste -s -d ' '`
  9. for i in $LIST; do patches=$(echo $patches + 1 | bc);done
  10. if [[ $branch =~ .*for-next.* ]]
  11. then
  12. start=HEAD
  13. # start=origin/for-next
  14. else
  15. start=origin/master
  16. fi
  17. tracking=`git rev-parse --abbrev-ref --symbolic-full-name @{u}`
  18. /usr/bin/echo "-----------------------[" $branch "]-----------------------"
  19. patches=$(echo $patches - 1 | bc);
  20. for i in $LIST; do
  21. if [ $patches -eq 1 ]; then
  22. cnt=" ^"
  23. elif [ $patches -eq 0 ]; then
  24. cnt=" H"
  25. else
  26. if [ $patches -lt 10 ]; then
  27. cnt=" $patches"
  28. else
  29. cnt="$patches"
  30. fi
  31. fi
  32. /usr/bin/git show --abbrev-commit -s --pretty=format:"$cnt %h %<|(32)%an %s %n" $i
  33. patches=$(echo $patches - 1 | bc)
  34. done
  35. #git log --reverse --abbrev-commit --pretty=format:"%h %<|(32)%an %s" $tracking..$branch
  36. #git log --reverse --abbrev-commit --pretty=format:"%h %<|(32)%an %s" ^origin/master ^linux-gfs2/for-next $branch

2、gitlog.id

  
    
    
  
  1. #!/bin/bash
  2. branch=$1
  3. if test "x$branch" = x; then
  4. branch=`git branch -a | grep "*" | cut -d ' ' -f2`
  5. fi
  6. tracking=`git rev-parse --abbrev-ref --symbolic-full-name @{u}`
  7. /usr/bin/echo "-----------------------[" $branch "]-----------------------"
  8. git log --reverse --abbrev-commit --pretty=oneline $tracking..$branch | cut -d ' ' -f1 |paste -s -d ' '

3、gitlog.id2

  
    
    
  
  1. #!/bin/bash
  2. branch=$1
  3. if test "x$branch" = x; then
  4. branch=`git branch -a | grep "*" | cut -d ' ' -f2`
  5. fi
  6. tracking=`git rev-parse --abbrev-ref --symbolic-full-name @{u}`
  7. git log --reverse --abbrev-commit --pretty=oneline $tracking..$branch | cut -d ' ' -f1 |paste -s -d ' '

4、gitlog.grep

  
    
    
  
  1. #!/bin/bash
  2. param1=$1
  3. param2=$2
  4. if test "x$param2" = x; then
  5. branch=`git branch -a | grep "*" | cut -d ' ' -f2`
  6. string=$param1
  7. else
  8. branch=$param1
  9. string=$param2
  10. fi
  11. patches=0
  12. tracking=`git rev-parse --abbrev-ref --symbolic-full-name @{u}`
  13. LIST=`git log --reverse --abbrev-commit --pretty=oneline $tracking..$branch | cut -d ' ' -f1 |paste -s -d ' '`
  14. for i in $LIST; do patches=$(echo $patches + 1 | bc);done
  15. /usr/bin/echo "-----------------------[" $branch "-" $patches "patches ]-----------------------"
  16. patches=$(echo $patches - 1 | bc);
  17. for i in $LIST; do
  18. if [ $patches -eq 1 ]; then
  19. cnt=" ^"
  20. elif [ $patches -eq 0 ]; then
  21. cnt=" H"
  22. else
  23. if [ $patches -lt 10 ]; then
  24. cnt=" $patches"
  25. else
  26. cnt="$patches"
  27. fi
  28. fi
  29. /usr/bin/git show --abbrev-commit -s --pretty=format:"$cnt %h %<|(32)%an %s" $i
  30. /usr/bin/git show --pretty=email --patch-with-stat $i | grep -n "$string"
  31. patches=$(echo $patches - 1 | bc)
  32. done

5、gitbranchcmp3

  
    
    
  
  1. #!/bin/bash
  2. #
  3. # gitbranchcmp3 <old branch> [<new_branch>]
  4. #
  5. oldbranch=$1
  6. newbranch=$2
  7. script=/tmp/compare_mismatches.sh
  8. /usr/bin/rm -f $script
  9. echo "#!/bin/bash" > $script
  10. /usr/bin/chmod 755 $script
  11. echo "# Generated by gitbranchcmp3.sh" >> $script
  12. echo "# Run this script to compare the mismatched patches" >> $script
  13. echo " " >> $script
  14. echo "function compare_them()" >> $script
  15. echo "{" >> $script
  16. echo " git show --pretty=email --patch-with-stat \$1 > /tmp/gronk1" >> $script
  17. echo " git show --pretty=email --patch-with-stat \$2 > /tmp/gronk2" >> $script
  18. echo " kompare /tmp/gronk1 /tmp/gronk2" >> $script
  19. echo "}" >> $script
  20. echo " " >> $script
  21. if test "x$newbranch" = x; then
  22. newbranch=`git branch -a | grep "*" | cut -d ' ' -f2`
  23. fi
  24. tracking=`git rev-parse --abbrev-ref --symbolic-full-name @{u}`
  25. declare -a oldsha1s=(`git log --reverse --abbrev-commit --pretty=oneline $tracking..$oldbranch | cut -d ' ' -f1 |paste -s -d ' '`)
  26. declare -a newsha1s=(`git log --reverse --abbrev-commit --pretty=oneline $tracking..$newbranch | cut -d ' ' -f1 |paste -s -d ' '`)
  27. #echo "old: " $oldsha1s
  28. oldcount=${#oldsha1s[@]}
  29. echo "Branch $oldbranch has $oldcount patches"
  30. oldcount=$(echo $oldcount - 1 | bc)
  31. #for o in `seq 0 ${#oldsha1s[@]}`; do
  32. # echo -n ${oldsha1s[$o]} " "
  33. # desc=`git show $i | head -5 | tail -1|cut -b5-`
  34. #done
  35. #echo "new: " $newsha1s
  36. newcount=${#newsha1s[@]}
  37. echo "Branch $newbranch has $newcount patches"
  38. newcount=$(echo $newcount - 1 | bc)
  39. #for o in `seq 0 ${#newsha1s[@]}`; do
  40. # echo -n ${newsha1s[$o]} " "
  41. # desc=`git show $i | head -5 | tail -1|cut -b5-`
  42. #done
  43. echo
  44. for new in `seq 0 $newcount`; do
  45. newsha=${newsha1s[$new]}
  46. newdesc=`git show $newsha | head -5 | tail -1|cut -b5-`
  47. oldsha=" "
  48. same="[ ]"
  49. for old in `seq 0 $oldcount`; do
  50. if test "${oldsha1s[$old]}" = "match"; then
  51. continue;
  52. fi
  53. olddesc=`git show ${oldsha1s[$old]} | head -5 | tail -1|cut -b5-`
  54. if test "$olddesc" = "$newdesc" ; then
  55. oldsha=${oldsha1s[$old]}
  56. #echo $oldsha
  57. git show $oldsha |tail -n +2 |grep -v "index.*\.\." |grep -v "@@" > /tmp/gronk1
  58. git show $newsha |tail -n +2 |grep -v "index.*\.\." |grep -v "@@" > /tmp/gronk2
  59. diff /tmp/gronk1 /tmp/gronk2 &> /dev/null
  60. if [ $? -eq 0 ] ;then
  61. # No differences
  62. same="[SAME]"
  63. oldsha1s[$old]="match"
  64. break
  65. fi
  66. git show $oldsha |sed -n '/diff/,$p' |grep -v "index.*\.\." |grep -v "@@" > /tmp/gronk1
  67. git show $newsha |sed -n '/diff/,$p' |grep -v "index.*\.\." |grep -v "@@" > /tmp/gronk2
  68. diff /tmp/gronk1 /tmp/gronk2 &> /dev/null
  69. if [ $? -eq 0 ] ;then
  70. # Differences in comments only
  71. same="[same]"
  72. oldsha1s[$old]="match"
  73. break
  74. fi
  75. oldsha1s[$old]="match"
  76. echo "compare_them $oldsha $newsha" >> $script
  77. fi
  78. done
  79. echo "$new $oldsha $newsha $same $newdesc"
  80. done
  81. echo
  82. echo "Missing from $newbranch:"
  83. the_missing=""
  84. # Now run through the olds we haven't matched up
  85. for old in `seq 0 $oldcount`; do
  86. if test ${oldsha1s[$old]} != "match"; then
  87. olddesc=`git show ${oldsha1s[$old]} | head -5 | tail -1|cut -b5-`
  88. echo "${oldsha1s[$old]} $olddesc"
  89. the_missing=`echo "$the_missing ${oldsha1s[$old]}"`
  90. fi
  91. done
  92. echo "The missing: " $the_missing
  93. echo "Compare script generated at: $script"
  94. #git log --reverse --abbrev-commit --pretty=oneline $tracking..$branch | cut -d ' ' -f1 |paste -s -d ' '

6、gitlog.find

  
    
    
  
  1. #!/bin/bash
  2. #
  3. # Find the upstream equivalent patch
  4. #
  5. # gitlog.find
  6. #
  7. cwd=$PWD
  8. param1=$1
  9. ubranch=$2
  10. patches=0
  11. script=/tmp/compare_upstream.sh
  12. echo "#!/bin/bash" > $script
  13. /usr/bin/chmod 755 $script
  14. echo "# Generated by gitbranchcmp3.sh" >> $script
  15. echo "# Run this script to compare the mismatched patches" >> $script
  16. echo " " >> $script
  17. echo "function compare_them()" >> $script
  18. echo "{" >> $script
  19. echo " cwd=$PWD" >> $script
  20. echo " git show --pretty=email --patch-with-stat \$2 > /tmp/gronk2" >> $script
  21. echo " cd ~/linux.git/fs/gfs2" >> $script
  22. echo " git show --pretty=email --patch-with-stat \$1 > /tmp/gronk1" >> $script
  23. echo " cd $cwd" >> $script
  24. echo " kompare /tmp/gronk1 /tmp/gronk2" >> $script
  25. echo "}" >> $script
  26. echo " " >> $script
  27. #echo "Gathering upstream patch info. Please wait."
  28. branch=`git branch -a | grep "*" | cut -d ' ' -f2`
  29. tracking=`git rev-parse --abbrev-ref --symbolic-full-name @{u}`
  30. cd ~/linux.git
  31. if test "X${ubranch}" = "X"; then
  32. ubranch=`git branch -a | grep "*" | cut -d ' ' -f2`
  33. fi
  34. utracking=`git rev-parse --abbrev-ref --symbolic-full-name @{u}`
  35. #
  36. # gather a list of gfs2 patches from master just in case we can't find it
  37. #
  38. #git log --abbrev-commit --pretty=format:" %h %<|(32)%an %s" master |grep -i -e "gfs2" -e "dlm" > /tmp/gronk
  39. git log --reverse --abbrev-commit --pretty=format:"ms %h %<|(32)%an %s" master fs/gfs2/ > /tmp/gronk.gfs2
  40. # ms = in Linus's master
  41. git log --reverse --abbrev-commit --pretty=format:"ms %h %<|(32)%an %s" master fs/dlm/ > /tmp/gronk.dlm
  42. cd $cwd
  43. LIST=`git log --reverse --abbrev-commit --pretty=oneline $tracking..$branch | cut -d ' ' -f1 |paste -s -d ' '`
  44. for i in $LIST; do patches=$(echo $patches + 1 | bc);done
  45. /usr/bin/echo "-----------------------[" $branch "-" $patches "patches ]-----------------------"
  46. patches=$(echo $patches - 1 | bc);
  47. for i in $LIST; do
  48. if [ $patches -eq 1 ]; then
  49. cnt=" ^"
  50. elif [ $patches -eq 0 ]; then
  51. cnt=" H"
  52. else
  53. if [ $patches -lt 10 ]; then
  54. cnt=" $patches"
  55. else
  56. cnt="$patches"
  57. fi
  58. fi
  59. /usr/bin/git show --abbrev-commit -s --pretty=format:"$cnt %h %<|(32)%an %s" $i
  60. desc=`/usr/bin/git show --abbrev-commit -s --pretty=format:"%s" $i`
  61. cd ~/linux.git
  62. cmp=1
  63. up_eq=`git log --reverse --abbrev-commit --pretty=format:"lo %h %<|(32)%an %s" $utracking..$ubranch | grep "$desc"`
  64. # lo = in local for-next
  65. if test "X$up_eq" = "X"; then
  66. up_eq=`git log --reverse --abbrev-commit --pretty=format:"fn %h %<|(32)%an %s" master..$utracking | grep "$desc"`
  67. # fn = in for-next for next merge window
  68. if test "X$up_eq" = "X"; then
  69. up_eq=`grep "$desc" /tmp/gronk.gfs2`
  70. if test "X$up_eq" = "X"; then
  71. up_eq=`grep "$desc" /tmp/gronk.dlm`
  72. if test "X$up_eq" = "X"; then
  73. up_eq=" Not found upstream"
  74. cmp=0
  75. fi
  76. fi
  77. fi
  78. fi
  79. echo "$up_eq"
  80. if [ $cmp -eq 1 ] ; then
  81. UP_SHA1=`echo $up_eq|cut -d' ' -f2`
  82. echo "compare_them $UP_SHA1 $i" >> $script
  83. fi
  84. cd $cwd
  85. patches=$(echo $patches - 1 | bc)
  86. done
  87. echo "Compare script generated: $script"

via: 

本文由  原创编译, 荣誉推出

以上是关于6 个方便的 Git 脚本 | Linux 中国的主要内容,如果未能解决你的问题,请参考以下文章

30 个方便的 Bash shell 别名 | Linux 中国

10 个增加 UNIX/Linux Shell 脚本趣味的工具 | Linux 中国

如何在 Emacs 中使用 Magit 管理 Git 项目 | Linux 中国

11 个鲜为人知的 Linux 命令

实习笔记1

常用 Git 命令清单