Git Commit Squash

If your commits on local not pushed to remote

combine local commits, you could follow this flow

Here is short video (only 3 minutes) and good explanation of git rebase -i usage.

list your local repository log

list your logs in oneline

If you want to combine these 3 commits (add6152, 3650100, 396a652) to 1 commit, execute this command

git rebase -i HEAD~3      # last three commits

list last three commits

Select which commit you want to squash (type s or squash are OK)

combine three commits to one

then press ESC, enter :wq! to save and exit.

comment out some commits message you don't need

Comment out some commits message you don’t need, press ESC, enter :wq! to save and exit.

comment out some commits message you don't need

Check log, you will see your local repository logs has combine to one commit

comment out some commits message you don't need

If your commits had pushed to remote

combine remote commits, you could follow this flow

list your repository logs

list your logs in oneline

# so you can create another branch from bugfix/UNV-1234 named bugfix/UNV-1234-for-squash
xshen@dln-l-xs01 MINGW64 /c/U2GitCode/git-test (bugfix/UNV-1234)
$ git checkout -b bugfix/UNV-1234-for-squash
Switched to a new branch 'bugfix/UNV-1234-for-squash'

# combine last 2 commits
$ git rebase -i HEAD~2

change one commit from pick to squash, see the screenshot below. press ESC, enter :wq! to save and exit.

select a commit you want to squash

change commit message, for example “UNV-1234 combine all commit to one commit”, then press ESC, enter :wq! to save and exit.

comment out commit message you don't want to display

# push your new create branch to remote.
git push -u origin bugfix/UNV-1234-for-squash

Jenkins troubleshooting summary

ERROR: Error cloning remote repo ‘origin’ timeout=10

Recently, my Jenkins build failed when execute git clone with following this error message: ERROR: Error cloning remote repo ‘origin’.

  1. first I suspect it is the network reason, maybe because clone from Bitbucket need took up a lot bandwidth during git clone and causing this disconnection. but when I try to git clone on the agent, it works well.
  2. Then I noticed the there is timeout=10 in the Jenkins console log, I suddenly remembered that I deleted a very large folder a few days ago from git repo, and this may cause the repo more bigger, so it may take more time do a complete clone and it exceeds the Jenkins default clone timeout 10.

Googling and finally I found this issue JENKINS-47660 which is the same problem as mine.

Read More

如何通过 Jenkins 进行资源的锁定和释放

业务场景

日常工作中需要切换到不同平台(包括 Linux, AIX, Windows, Solris, HP-UX)不同的版本进行开发和验证问题,但是由于虚拟机有限,并不能保证每个开发和测试都有所以平台的虚拟机并且安装了不同的版本,因此准备各种各样的开发和测试环境会花费很长时间。

Read More

在大型企业里维护多分支流水线

Jenkins 是 DevOps 领域里非常好的 CI/CD 工具,它凭借其独特的功能,几乎可以满足你一切的的业务要求。其中一个独特的功能是多分支流水线(Multi-branch 流水线),可以动态配置流水线。但是,随着公司的发展,单独的多分支流水线并不能完全满足你的所有需求,特别是在涉及大型企业时,你需要考虑流水线的集中管理,治理,稳定性,限制和安全性等其他事项。因此对于具有 Jenkins 流水线的大规模 CI/CD 环境,你需要添加之前没有想到的更多功能。

Read More

Git branching strategy

随着近些年 Git 的快速普及,想必无论开发还是测试在日常工作中都要用到 Git。

对于刚刚接触的 Git 的人来说,打开一个 Git 仓库,面对十几个甚至几十个分支时,有的人不理解,有的人云里雾里,为什么会创建这么多分支?

对于开发需要知道如何通过 Git 分支来管理产品的开发和发布,尤其是对于大型的项目的开发,只有 master 和 develop 分支是无法满足产品管理和发布要求的,我们还需要其他分支以便更好的管理产品代码。

对于测试更多的了解开发过程及分支管理有助于测试及开展自动化测试用例,可以针对不同的分支进行测试用例的编写,在以后回归测试里可以通过分支或是 tag 找到对应的测试用例。

Read More

通过 Jenkins 来提交修改的代码 git push by Jenkins

在持续集成中,你可能需要通过 Jenkins 来修改代码,并且将修改后的代码提交到Git仓库里。怎么做呢?最方便的做法还是 Jenkins 提供对应的插件,但是很遗憾我没找到合适的。另外我也觉得通过脚本的方式来实现会更加稳定,不用担心 Jenkins 以及插件升级带来潜在不好用的可能。

Read More

Execute sudo without password

在使用 Jenkins pipeline 的时候,在 Linux 需要用 root 来执行,我想通过 Jenkins pipeline 的语法来解决,但是只找到这种方式:SSH Pipeline Steps

Read More

Hexo 添加 Disqus 留言功能

在你的 Hexo 网站添加 Disqus

去 Disqus 创建一个账号,在这个过程中有需要选择一个 shortname,完成后,你可以在设置页码找到你的 shortname

https://YOURSHORTNAMEHERE.disqus.com/admin/settings/general

在你 Hexo 博客里打开 _config.yml, 然后输入 disqus_shortnameand: YOURSHORTNAMEHERE,像这样:

Read More

Jenkinsfile example - 实现交互、clone 多个仓库以及 git push

这个pipeline里包含了如下几个技术:

  • 如何使用其他机器,agent
  • 如何使用环境变量,environment
  • 如何在build前通过参数化输入,parameters
  • 如何使用交互,input
  • 如何同时clone多个repos
  • 如何进行条件判断,anyOf

Read More

Git 管理

查找是否有遗漏提交

从一个分支找到所有的 commit 和 ticket 号,然后去另外一个分支去查找这些提交是否也在这个分支里。

Read More