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

Thursday, March 9, 2017

git checkout old commit and create new branch

1)
$git checkout 40d449d20264925b89b84e6f1425de83babccc5a -b v3_5_0_2
Switched to a new branch 'v3_5_0_2'
$

2)
$git branch
  master
* v3_5_0_2
$

3)

Thursday, November 26, 2015

How to git cherry-pick fix conflicts and edit commit message

1)
* -e --> to edit commit message
$ git cherry-pick -e ffed960e08b1aa340e020decc7cb5a735e7185ce
error: could not apply ffed960... update to working version of contrail module
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add ' or 'git rm '
hint: and commit the result with 'git commit'

2)
$git diff
Fix conflict

3)
$ git add Puppetfile

4)
$ git status
On branch kilo_multinode_contv2
You are currently cherry-picking commit ffed960.
  (all conflicts fixed: run "git cherry-pick --continue")
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:

    modified:   Puppetfile
    modified:   manifests/neutron/contrail/fip_pool.pp

5)
$ git cherry-pick -e --continue
[kilo_multinode_contv2 ba0dd5a] [bode] update to working version of contrail module
 Author: Dan Bode
 2 files changed, 7 insertions(+), 2 deletions(-)

6)
abort cherry-pick which has conflict and not required.
$ git cherry-pick --abort



Monday, August 10, 2015

How to git cherry-pick commit from another/upstream repository

1)
Clone forked repo
#git clone https://github.com/JioCloud/contrail-third-party.git
#cd
contrail-third-party.git

2)
Check all existing branches
#git branch
  branch1
  branch2
* master

3)
Add upstream remote (upstream repo) and name it "upstream_remote"
#git remote add upstream_remote https://github.com/Juniper/contrail-third-party.git

4)
Check all remotes
#git remote -v
upstream_remote    https://github.com/Juniper/contrail-third-party (fetch)
upstream_remote    https://github.com/Juniper/contrail-third-party (push)
origin    https://github.com/JioCloud/contrail-third-party (fetch)
origin    https://github.com/JioCloud/contrail-third-party (push)

5)
Fetch the latest version of master (fetch all branches) from remote "upstream_remote"
#git fetch upstream_remote

6)
Goto the branch where you want to apply the commits.
$git checkout R1.10
* This "R1.10" branch is in "origin" remote

7)
cherry-pick the commit from newly added  upstream_remote and apply.
$git cherry-pick [commit-id]

* You can use $git log command to find the commit-id from upstream_remote branches.
* Example:
   $git log -n 5 upstream_remote/branch_name





Wednesday, November 19, 2014

How To git change url of remote origin and pull without conflict

1)
Set new URL for remote 'origin'

#git remote set-url origin https://github.com/myrepo/MYPRO.git

2)
Fetch data from new remote 'origin'

#git fetch origin

3)
Pull and rebase changes from new remote 'origin'

#git pull --rebase origin
https://www.atlassian.com/git/tutorials/syncing/git-pull

4)
Pull changes from branch 'migration_django_15' in the new remote 'origin'

#git pull origin migration_django_15

Tuesday, November 18, 2014

How To git checkout branches from different remotes

1)
Add your remote

#git remote add github-remote https://github.com/myrepo/MYPRO.git

2)
Fetch remote

#git fetch github-remote

3)
Checkout the branch "migration_django_15" from the remote "github-remote" and rename to "migration_django_15_github"

#git checkout -b migration_django_15_github --track github-remote/migration_django_15

4)
Now in local machine, I am in "migration_django_15_github" branch.
Pull the latest changes from "migration_django_15_github" branch in the remote https://github.com/myrepo/MYPRO.git

#git pull





Monday, November 17, 2014

Git remove file or folder from all commits in all branches and tags

1)
Goto git repo

2)
Remove a file or folder  from all commits in all branches and tags
#git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch FOLDERNAME-OR-FILENAME" -- --all

* Replace FOLDERNAME-OR-FILENAME with file or folder you want to remove

Monday, April 28, 2014

Git How to merge a branch into master branch (Move all new commits one by one from our branch to master branch)

1)
#git clone https://github.com/myrepo/horizon.git

2)
#cd horizon
*Now you are in master branch

3)
*Checkput new feature branch
#git checkout new_feature

4)
*Go back to master branch
#git checkout master

5)
*Check log
#git log -n 3

6)
*Merge the branch "new_feature" into "master"
#git merge new_feature

7)
*Check log
#git log -n 3
8)
#Push master to remote repo (https://github.com/blabla)
#git push remote master

Tuesday, April 22, 2014

How to Git create a new branch and push to github.com

1)
Create a branch "new_branch"
#git branch new_branch

2)
Switch to the branch "new_branch"
#git checkout new_branch

3)
Find name of the remote
#git remote -v

4)
Push the branch "new_branch" to remote "origin"
#git push origin new_branch

Friday, March 21, 2014

Git How to Find a commit id by searching in commit messages

1)
#git clone https://github.com/openstack/python-keystoneclient.git
#cd python-keystoneclient


2)
Search
------------

#git log --grep="Closes-Bug: 1047867"
commit 6cb1cd8c5a334406027c8859ba9b5a3abc07cca7
Author: Divyesh Khandeshi
Date:   Tue Jan 7 16:41:17 2014 -0500

    Consistently support kwargs across all v3 CRUD Manager ops
   
    Co-Authored-By: Saju Madhavan
    Closes-Bug: 1047867
    Implements: blueprint extensible-crud-manager-operations
    Change-Id: I64e11bcf3797eb84e4695605daea9749259d78ec

3)
https://github.com/openstack/python-keystoneclient/commit/6cb1cd8c5a334406027c8859ba9b5a3abc07cca7

Form the above link you can find the name of the tags. You can use that tag name to checkout stable version.

You can slso use following command to find the name of the tags (stable version) which contains our commit

#git tag --contains 6cb1cd8c5a334406027c8859ba9b5a3abc07cca7
0.5.0
0.5.1
0.6.0


4)
You can checkout form the tag like

#git checkout tags/0.6.0

5)
https://launchpad.net/ubuntu/+source/python-keystoneclient/1:0.6.0-0ubuntu1/+build/5616557

Tuesday, January 28, 2014

Git How to keep all our commits on top of upstream commits

1)
Goto new devstack env
#cd /opt/stack/horizon

2)
Check default/existing remote repo and location
#git remote -v
origin    git://git.openstack.org/openstack/horizon.git (fetch)
origin    git://git.openstack.org/openstack/horizon.git (push)

3)
Add new remote repo.
Location of our remote repo where we are saving our horizon changes.
#git remote add mycld https://github.com/myCloud/horizon.git
#git remote -v
mycld    https://github.com/myCloud/horizon.git (fetch)
mycld    https://github.com/myCloud/horizon.git (push)
origin    git://git.openstack.org/openstack/horizon.git (fetch)
origin    git://git.openstack.org/openstack/horizon.git (push)

4)
Grab all branches and tags from the remote 'mycld'.
git fetch doesn’t touch your working tree at all, so gives you a little breathing space to decide what you want to do next.
git pull pulls from a remote branch and merges it.
git fetch only fetches from the remote branch but it does not merge
git pull = git fetch + git merge
#git fetch mycld
#git branch
*master

5)
Checkout the branch my_homepage from the remote 'mycld'.
#git checkout --track mycld/my_homepage
#git branch
* my_homepage
  master

6)
Note, right now I am in the branch 'mycld/my_homepage'.
#git pull

7)
Note, right now I am in the branch 'mycld/my_homepage'.
So the following command will takes commits which are only in the branch 'mycld/my_homepage'
and not in 'origin/master' and store it in temporary location.
Then appy all new commits (which are not in 'mycld/my_homepage') from 'origin/master' to 'mycld/my_homepage'.
Then try to restore all temporary stored commits one by one to 'mycld/my_homepage'.
So after this, In 'mycld/my_homepage' we can again see all our commits on top plus new commits from 'origin/master'.
#git rebase master

8)
Run 'git diff' to see the conflict
#git diff

9)
#Fix all conflicts manually (resolve all conflicts)

10)
Prepare the resoved files for commit
#git add name_of_modified_file(s)

11)
This command will automatically commit all resolved files and move to the next commit.
So we don't need to commit the resoved files manually.
#git rebase --continue

12)
#Repeat the steps from 8 to 11 until all the conflicts get fixed

13)
Optional
#git pull mycld my_homepage

14)
Optional
#Fix conflict manually and #git commit -a

15)
Push the rebased code to remote repo where we are saving our horizon changes.
#git push mycld my_homepage

Thursday, January 23, 2014

Git How to modify a specified commit

You can use git rebase, for if you want to modify back to commit hu783vgt45.

1)
$ git rebase --interactive hu783vgt45^
In the default editor, modify 'pick' to 'edit' in the line whose commit you want to modify.
Here 'edit' will apply the diff of commit you selected and store all the commits which came after that in a temporary location.

2)
Make your changes to the commit hu783vgt45 you selected and then stage (prepare for commit) them with
$ git add


3)Commit the changes of hu783vgt45 (here you can change commit message)
$ git commit --amend

4)
To return back to the previous head commit (original last commit).
Restore all commits which stored in the temporary location during rebase.
$ git rebase --continue

Wednesday, January 15, 2014

Git How to move all commits to another repository using git format-patch and git am

1)
Goto Project folder. Your first repo
#cd /home/saju/project1/src

2)
Take diffs
#git format-patch -o /home/saju/patch_backup/ 0aa25e5ce31ab05db98d258f90850f478303dc23~..699a6a0decd6889b7cfbfc6fc80ab641965385b4

3)
Goto your new second repo
#/home/saju/project2/src



4)
Creaet git repo, if not there
#git init
#git add *
#git commit -m "create new git repo: initial commit"

5)
Apply patch
#git am --reject /home/saju/patch_backup/0001-Migration-to-Django-1.5-Initial-Commit.patch

6)
Check for rejected files
#find . -name "*.rej"

7)
Some checks (Optional)
#git diff
#git log

8)
If patch failed, then we have to add all chaged file and run "git am --resolved"
#git add -A
#git diff
#If there any conflict, fix that, then
#git am --resolved
#git log

9)
Delted all rejected filed "*.rej" and apply the next patch (Step-5)
#find . -name '*.rej' -exec rm {} \;

Thursday, January 9, 2014

How To Checkout From review.openstack.org And Push Changes Back Again For Review

1)
#git fetch ssh://sajuptpm@review.openstack.org:29418/openstack/python-keystoneclient refs/changes/81/65381/2 && git checkout FETCH_HEAD -b test_branch
From ssh://review.openstack.org:29418/openstack/python-keystoneclient
 * branch            refs/changes/81/65381/2 -> FETCH_HEAD
Switched to a new branch 'test_branch'


2)
#git branch
  master
* test_branch

3)
#git remote -v
origin    https://github.com/openstack/python-keystoneclient.git (fetch)
origin    https://github.com/openstack/python-keystoneclient.git (push)

4)
#git review -s
Could not connect to gerrit.
Enter your gerrit username: sajuptpm
Trying again with ssh://sajuptpm@review.openstack.org:29418/openstack/python-keystoneclient.git
Creating a git remote called "gerrit" that maps to:
    ssh://sajuptpm@review.openstack.org:29418/openstack/python-keystoneclient.git

This repository is now set up for use with git-review.
You can set the default username for future repositories with:
  git config --global --add gitreview.username "sajuptpm"

5)
#git remote -v
gerrit    ssh://sajuptpm@review.openstack.org:29418/openstack/python-keystoneclient.git (fetch)
gerrit    ssh://sajuptpm@review.openstack.org:29418/openstack/python-keystoneclient.git (push)
origin    https://github.com/openstack/python-keystoneclient.git (fetch)
origin    https://github.com/openstack/python-keystoneclient.git (push)

6)
#git remote update
Fetching origin
Fetching gerrit

7)
#git branch
  master
* test_branch

8)
#git checkout master
Switched to branch 'master'

9)
#git branch
* master
  test_branch

10)
#git pull --ff-only origin master
From https://github.com/openstack/python-keystoneclient
 * branch            master     -> FETCH_HEAD
Already up-to-date.

11)
#git branch
* master
  test_branch

12)
#git remote -v
gerrit    ssh://sajuptpm@review.openstack.org:29418/openstack/python-keystoneclient.git (fetch)
gerrit    ssh://sajuptpm@review.openstack.org:29418/openstack/python-keystoneclient.git (push)
origin    https://github.com/openstack/python-keystoneclient.git (fetch)
origin    https://github.com/openstack/python-keystoneclient.git (push)

13)
#git checkout test_branch
Switched to branch 'test_branch'

14)
#git branch
  master
* test_branch

15)
#git diff

16)
*See comment and diff of last commit
#git show

17)
Make your changes

18)
a)
*If you want to save your changes as new commit
#git commit -a

b)
*If you want to append your changes to last commit
#git commit --amend

19)
*Push your Changes to https://review.openstack.org
#git review

20)
Goto https://review.openstack.org

Friday, January 3, 2014

OpenStack How to Commit and Submit Changes For Review

OpenStack How to Commit and Submit Changes For Review

OpenStack Training
http://docs.openstack.org/training-guides/content/operator-getting-started-lab.html

OpenStack Projects How to resubmit patch set

OpenStack Projects How to submit new changes after review from review.openstack.org

1)
#git remote -v
gerrit    ssh://sajuptpm@review.openstack.org:29418/openstack/python-keystoneclient.git (fetch)
gerrit    ssh://sajuptpm@review.openstack.org:29418/openstack/python-keystoneclient.git (push)
origin    https://github.com/openstack/python-keystoneclient.git (fetch)
origin    https://github.com/openstack/python-keystoneclient.git (push)

2)
#git branch
* bug/1047867
  master

3)
Make your new changes for the bug "bug/1047867".
Then, Commit your changes
#git commit -a --amend
or
#git commit file1 file2 --amend


* We are using --amend, because this fix is part of our lat commit.
* So we can append this changes to last commit and use the message lat commit.

4)
Goto master branch

#git checkout master

5)
#git branch
  bug/1047867
* master

6)
Update master branch of remote 'origin'

#git pull origin master

7)
Goto "bug/1047867" branch

#git checkout bug/1047867

8)
#git rebase -i master
This command does following operations
*Take backup of last commit from the branch "bug/1047867"
*Apply all changes from "master" branch to "bug/1047867"
*Apply backup-ed commit back to the branch "bug/1047867"

9)
Run 'git log', You can see your commit in the first place.

#git log

10)
Now your branch "bug/104786" is updated


11)
Make your new changes (related to bug:104786) in "bug/104786" branch


12)
Run following testings

*Unit test
#./run_tests.sh
*PEP8 cleaning
#./run_tests.sh --pep8

or
./run_tests.sh -d
./run_tests.sh -p

13)
Make your changes (In any) for the bug "bug/1047867".
Then, Commit your changes
#git commit -a --amend
or
#git commit file1 file2 --amend


* We are using --amend, because this fix is part of our lat commit.
* So we can append this changes to last commit and use the message lat commit.

14)
Upload your changes to Gerrit for review

#git review

15)
Goto https://review.openstack.org and login

There you can see your changes and status of review.

Friday, December 13, 2013

Git How to revert Last Commit and Difference Between Soft and Hard Reset or Revert

#git log
#git reset --soft HEAD~1 # use --soft if you want to keep your local changes and revert last commit
#git reset --hard HEAD~1 # use --hard if you want to revert your changes and revert last commit
#git log


Tuesday, December 10, 2013

Git How to revert last commit

How to revert last commit
#git log
#git reset --soft HEAD~1 # use --soft if you want to keep your local changes and revert last commit
#git reset --hard HEAD~1 # use --hard if you want to revert your changes and revert last commit
#git log



How to revert last two commit
#git log
#git reset --soft HEAD~2 # use --soft if you want to keep your local changes and revert last commit
#git reset --hard HEAD~2 # use --hard if you want to revert your changes and revert last commit
#git log

How to revert last three commit
#git log
#git reset --soft HEAD~3 # use --soft if you want to keep your local changes and revert last commit
#git reset --hard HEAD~3 # use --hard if you want to revert your changes and revert last commit
#git log

Friday, December 6, 2013

Git commit message how to change default editor to VM

1)
#git config --global core.editor "vim"

2)
#git commit myfile.py
or
#git commit -a

Monday, December 2, 2013

How to Openstack Devstack Switch git Branch (Keystone)

1)
saju@saju-VirtualBox:/opt/stack/keystone$
saju@saju-VirtualBox:/opt/stack/keystone$ git remote add sajucld https://github.com/kwss/keystone.git
saju@saju-VirtualBox:/opt/stack/keystone$

2)
saju@saju-VirtualBox:/opt/stack/keystone$ git remote -v
sajucld    https://github.com/kwss/keystone.git (fetch)
sajucld    https://github.com/kwss/keystone.git (push)
origin    https://github.com/openstack/keystone.git (fetch)
origin    https://github.com/openstack/keystone.git (push)
saju@saju-VirtualBox:/opt/stack/keystone$

3)
saju@saju-VirtualBox:/opt/stack/keystone$ git fetch sajucld
remote: Counting objects: 1172, done.
remote: Compressing objects: 100% (512/512), done.
remote: Total 914 (delta 578), reused 724 (delta 398)
Receiving objects: 100% (914/914), 316.91 KiB | 27.00 KiB/s, done.
Resolving deltas: 100% (578/578), completed with 93 local objects.
From https://github.com/kwss/keystone
 * [new branch]      bp/role-mapping-service-keystone -> sajucld/bp/role-mapping-service-keystone
 * [new branch]      feature/keystone-v3 -> sajucld/feature/keystone-v3
 * [new branch]      fed-plugin-moonshot -> sajucld/fed-plugin-moonshot
 * [new branch]      federated_auth_plugin -> sajucld/federated_auth_plugin
 * [new branch]      idp-service -> sajucld/idp-service
 * [new branch]      kent-federated-april -> sajucld/kent-federated-april
 * [new branch]      master     -> sajucld/master
 * [new branch]      role-mapping -> sajucld/role-mapping
 * [new branch]      stable/diablo -> sajucld/stable/diablo
 * [new branch]      stable/essex -> sajucld/stable/essex
 * [new branch]      stable/folsom -> sajucld/stable/folsom
saju@saju-VirtualBox:/opt/stack/keystone$

4)
saju@saju-VirtualBox:/opt/stack/keystone$ git checkout --track sajucld/feature/keystone-v3
Branch feature/keystone-v3 set up to track remote branch feature/keystone-v3 from sajucld.
Switched to a new branch 'feature/keystone-v3'
saju@saju-VirtualBox:/opt/stack/keystone$

5)
saju@saju-VirtualBox:/opt/stack/keystone$ git branch
* feature/keystone-v3
  master
saju@saju-VirtualBox:/opt/stack/keystone$

6)
Switch to working devstack branch
#git checkout mater

Goto devstack screen
#screen -x
* Press "Ctrl +  a + 1", to goto keystone log
* Press "Ctrl + c" to stop keystone service
* Press Up arrow and press Enter to Start keystone service again

7)
Switch to dev/testing branch
#git checkout feature/keystone-v3

Goto devstack screen
#screen -x
* Press "Ctrl +  a + 1", to goto keystone log
* Press "Ctrl + c" to stop keystone service
* Press Up arrow and press Enter to Start keystone service again