Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Monday, February 17, 2014

How quickly revert last pushed commit

I found that operation of giving permission for awhile in gitolite force me  do commit-push and revert of changes in few minutes , here is how to do revert quickly for last pushed commit (it hash is on output):

02:45 PM ~/java/git/gitolite-admin/conf [master|● 1] $ git commit -m "fix for hotfix branch"
[master 9d8f0ae] fix for hotfix branch
 1 file changed, 1 insertion(+), 1 deletion(-)
02:45 PM ~/java/git/gitolite-admin/conf [master ↑·1|✔] $ git push
Counting objects: 10, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 385 bytes | 0 bytes/s, done.
Total 4 (delta 1), reused 0 (delta 0)
To git@git.mycompany.com:gitolite-admin
   040e849..9d8f0ae  master -> master
02:46 PM ~/java/git/gitolite-admin/conf [master|✔] $ git revert 9d8f0ae

You can test that hash-code is the same by review of logs before revert:
02:45 PM ~/java/git/gitolite-admin/conf [master|✔] $ git log
commit 9d8f0ae3a56152067341c4f2c301c4d232dcbda0

Monday, January 6, 2014

Git branching models review


Good explanation for well known branching models : https://www.atlassian.com/git/workflows
git-flow: http://nvie.com/posts/a-successful-git-branching-model/
git-flow script: https://github.com/nvie/gitflow
interesting explanation of git-flow: http://danielkummer.github.io/git-flow-cheatsheet/

jgit-flow: https://bitbucket.org/atlassian/maven-jgitflow-plugin/wiki/Home
http://blogs.atlassian.com/2013/04/git-flow-comes-to-java/
http://blogs.atlassian.com/2013/05/maven-git-flow-plugin-for-better-releases/


just another workflow (Dymitruk Model): http://dymitruk.com/blog/2012/02/05/branch-per-feature/

another overusage of git (but helps its owners): http://stackoverflow.com/questions/19695127/git-workflow-review


One man have the same problem as we (Feature branch vs Jenkins): http://www.giorgenes.com/2012/04/some-thoughts-on-continuous-integration.html


So here is summary:
- git workflow is never ideal and never suit all needs;
- git workflow is reflection of release approaches and language nature and nuances of current project (
 a) existence of CI and level of CI fanaticism (to automate all or have special person that manage CI),
 b) QA/UAT staging environment and how that team approve release to be applied to production,
 c) special engineer that will focus on releases,
 d) versions bump approach,
 e) project structure and building nuances (maven, ant, gradle, scripts or compiled language),
 f) frequency of releases and hotfixes,
 g) requirement of previous versions support or back-porting policy,
 h) project manager that can always apply pull requests, or any code review system (gerrit)
 ....
).
- every "enterprise-successful" workflows create some script/plugin to follow its model with hiding all git commands, and ease git management.
- if you do not like over-engineering, so stay with simplest branching model (all in master, feature branches goes base on master) 

Wednesday, January 1, 2014

Continuous testing of feature branching model workflow in Jenkins

Interesting approach:
https://wiki.jenkins-ci.org/display/JENKINS/Feature+Branch+Notifier+Plugin

http://zeroturnaround.com/rebellabs/things-to-consider-when-featuring-branching-with-continuous-integration/

I liked following idea:

unfortunately this plugin does not support GIT, so smth should be created for GIT ...

list of all triggers for Jenkins is here.

there is a problem with idea of testing of all branches :
jenkins will show latest status of build it most likely to be topic branch - ever red jenkins is not a good approach as topic branch is designed for keeping incomplete changes and they will always exists .

so Jenkins somehow need to show status only from main branch all other are just for information, in other words aggregation of statuses or custom rule to make global status base on set of branches ..... new plugin :) .

Approach of how to ignore some branches in jenkins by regex

Saturday, November 23, 2013

How to merge github wiki changes from one repository to another


Case:
User forked a repository on GitHub and wiki pages are also forked, user do changes to wiki, but there is no way to send pull request for wiki changes, but Wiki is just another sub repository in GitHub repo, so admin of original repository have to do merge manually.

Example:
source wiki: https://github.com/VadimPanasiuk/sevntu.checkstyle.wiki.git
target/original wiki: https://github.com/sevntu-checkstyle/sevntu.checkstyle.wiki.git

Source of wisdom for massive squash.

Commands:
git clone https://github.com/sevntu-checkstyle/sevntu.checkstyle.wiki.git
cd sevntu.checkstyle.wiki.git
git fetch https://github.com/VadimPanasiuk/sevntu.checkstyle.wiki.git master:master-Vadim
git checkout master-Vadim

#checkout to last non-Vadim's commit  
git reset --hard 34a2f8e627dd6209f4928b6f66a37368789ab492

# do massive squash of all Vadim's changes
git merge --squash HEAD@{1}          
git commit -m "How to use SevNTU Checkstyle in Intellij IDEA (markdown)"
git checkout master

# cherry-pick newly squashed  commit
git cherry-pick cbe1915a65d80769d56f4fbd9a60dd0b88c8c049    

git push


If wiki was forked from latest state of original wiki, you can do it a bit simpler:
git clone https://github.com/sevntu-checkstyle/sevntu.checkstyle.wiki.git
cd sevntu.checkstyle.wiki.git
git pull https://github.com/VadimPanasiuk/sevntu.checkstyle.wiki.git master
# squashing all Vadim's changes in one 
git push origin master

Friday, September 6, 2013

Sync local git repository with remotes github and bitbucket

It is common case when you need sync sources between few remote repositories of git, mostly one of them is backup mirror or you have two communities and do not want to bother them what is better github or bitbucket.

#recheck what remotes you have already
git remote

# add link to github and bitbucket remote repo
git remote add github git@hithub.com:my-repo-name.git
git remote add bitbucket https://bitbucket.org/user/my-repo-name
git push -u github master
git push -u bitbucket master

#Somebody sent you fixes to bitbucket rep - pull it from bitbucket and push github
git pull bitbucket
git push github

Wednesday, May 1, 2013

How to split repository into two repositories


Source of wisdom.

We have infra repository that is have folder git_tool that is going to be new repository now.

State of repository "infra" before split:
jenkins_checks
svn2git
git_tools
build-release.sh              

Task: move "git_tools" to separate repository "infra_new".

Steps:
1. Create new repo for "git_tools" only
$ git clone  git@git.yourserver.com:infra
$ cd infra/
$ git filter-branch --prune-empty --index-filter 'git rm --cached --ignore-unmatch jenkins_checks/* sb-svn2git/* build-release.sh eclipse-compiler-warnings.epf ' HEAD
$ gitk --all
$ git remote add origin https://git@git.yourserver.org/infra_new.git
$ git push -u origin --all

2. Remove all history remnants from old "infra" repo:

$ git clone  git@git.yourserver.com:infra
$ cd infra/
$ git filter-branch --prune-empty --index-filter 'git rm --cached --ignore-unmatch git_tools/*' HEAD
$ gitk --all
$ git push -u origin --all --force

Saturday, April 13, 2013

Visual merge tools to resolve conflicts

Git visual merge in conflict:
http://www.gitguys.com/topics/merging-with-a-gui/

Meld - Works fine, but not intuitive.


sudo apt-get install meld
git mergetool -t meld
Main idea is to merge left and right versions to middle version and press Cntl+s.


kdiff3 - more intuitive and more settings.

sudo apt-get install kdiff3
git mergetool -t kdiff3


After that launch "git clean -f" to remove all un-tracked files.
It also possible to adjust git to avoid temp files creation
"git config --global mergetool.keepBackup false"

of adjust  your merge tool:
- Meld - does not have that feature
- kdiff3's settings are set to not create a backup:
Configure/Options => Directory Merge => Backup Files (*.orig)

Wednesday, March 27, 2013

Problem with development-master git workflow

If you have development-master git workflow and you have hotfixes to master that were cherry-picked to development - then you need to merge all to master back - you will not have Fast-forward merge (so you loose commit/comment/tag history).

To keep history you need rollback to common point in time, and to merge from that point, and to preserve hot-fix history you need "merge -s ours":




# backup for master in special branch
git fetch -p
git checkout -b release_1_3
git push origin release_1_3
# reset master to common commit with development 
git checkout master 
git reset b666156da5d1756ddfe7123ed4f1688f9c69cf6a --hard
git push --force
git clean -fd
# fast forward merge with development
git merge development 
git push

#do fake merge merge to keep hotfixes in history of master "-s ours"
git merge -s ours release_1_3

#drop temporal branch
git branch -D release_1_3
git push origin :release_1_3




Sunday, January 20, 2013

How to show git branch/status information in bash

extension for terminal/command line to use git more effectively:

For Mac users, (zsh): https://github.com/olivierverdier/zsh-git-prompt

For bash(works fine for Ubuntu): https://github.com/magicmonty/bash-git-prompt
I do following update for /home/USER/.bash/gitprompt.sh :
PROMPT_START="$WHITE$Time12a $Yellow$PathShort$ResetColor"
PROMPT_END=" $ "

For simple branch show(works very fast), (link second comment):
Simply add following line it ~/.bashrc
PS1='[\u@\h`__git_ps1` \W]\$ '



Wednesday, December 26, 2012

Git - merge till certain commit

Case: you need merge your master with with development branch but till certain commit(not till HEAD ) in development branch

it is simply:
-- I presume you are at development branch --
git checkout master
git merge 37e4218a4d51ad44952d30a5906cbe6b2e0a54d2

or do it by tag name:
git merge 0.5.10

and you will merge till this(37e421) commit, that is located in development branch.

Tuesday, December 18, 2012

Git commands to remember

Here I  will post command that usually use but sometime forget syntax, so rewriting them again with explanation help me to remember them :) :

remove all files from staging area - "git reset HEAD"

add to staging area only modified files - "git add -u"

remove all newly created files from working folder - "git clean -f"

change comment of the last commit - "git commit --amend"

get all remote branches to local repository - "git fetch"

create local branch base on existent remote branch - "git checkout -b development remotes/origin/development"

push to remote branch with 'force' after rebase - "git push --force origin SYS-551"

create new branch base on non commited changes - "git checkout -b short-status-form-sb" after that do "git add filepath ; ...."

push to remote newly created local branch - "git push origin my-new-feature"

show history of changes in terminal - "git log --oneline --decorate --graph"
show history of changes in UI - "gitk" or "gitk --all"

remove branch from local repository - "git branch -D SYS-551"

remove branch from remote repository  - "git push origin --delete SYS-551"

SVN style looks for logs output - "status -sb"

See all changes that are going to be pushed - "git diff --stat origin/master" or "git diff origin/master".

Get only the work your current topic branch has introduced since its common ancestor with master: "git master...test"

Revert one commit (revert changes that were done by commit) "git revert <SHA-1>"

Remove last commit completely from local repo - "git reset HEAD~1 --hard"

Find out which branch contains a change - "git branch --contains 50f3754"

Find out if a change is part of a release - "git name-rev --name-only 50f3754"

Get rid of all changes/commits in branch to remote git state "git reset --hard origin"

Convenient aliases, source:
git config --global alias.st "status -sb"
git config --global alias.ci commit
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.bra "branch -a"
git config --global alias.chp cherry-pick
git config --global alias.pr "pull --rebase"
git config --global alias.bl "blame -b -w"
git config --global alias.cia "commit --amend"
git config --global alias.lg "log --pretty=format:'%h was %an, %ar, message: %s' --graph"
git config --global alias.who "shortlog -s --"

from Daniil Yaroslavtsev:
git config --global alias.l "log --graph --pretty=format:'%Cred%h%Creset %C(bold blue)<%an>%Creset%C(yellow)%d%Creset %s %Cgreen(%cr)' --abbrev-commit --date=relative"

Tuesday, December 11, 2012

How to create new repo at gitolite



1. get access to gitolite-admin repository

2. clone it and do changes to git/gitolite-admin/conf/gitolite.conf

3. do push

4. update Cgit website configuration at git.yourcomapny.com file /etc/cgitrc

5. provide mail notifications: copy 'config' from existing repo to new repo at server.


"<repo>/config" content:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = true
[hooks]
        mailinglist = git-commit@company.com
        emailprefix="[GIT] "
    showrev = "echo "All Branches: "; git branch; echo; echo "Summary of changes:"; git log $oldrev..$newrev; echo; echo; git diff-tree -p --stat --summary --find-copies-harder $oldrev..$newrev;"




To automate all this steps please read this.

Attention: command for 'showrev' is not ideal and send empty mail in case of branch merges, and branch removal.

Monday, December 3, 2012

Gitolite - Change default config template file for repositories

We use gitolite for git server, and we use mail notifications after any push to repositories to manage and be notified about changes that are done by other developer.

After push in gitolite-admin repository, I need to login to git server and manually copy hook file and config for hook:
/home/git/repositories/REPO-NAME.git/config
/home/git/repositories/REPO-NAME.git/hooks/post-receive

My thread in google group to make automatically.


Monday, November 5, 2012

Convert SVN project to GIT

sudo apt-get install git-svn

There is a good manual to moving projects from SVN to GIT (In Russian):
http://habrahabr.ru/post/144626/

To get list of all users for user-map:
svn log > log_all.txt
cat log_all.txt | grep "^r[0-9]" | cut -d" " -f3 | sort | uniq -c > svn-git-users-map.txt

Thursday, September 20, 2012