Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
dev:using_git [2009/09/03 19:00]
hjunes add A typical short working cycle in git
dev:using_git [2021/04/01 03:31]
tedfelix
Line 1: Line 1:
-Before continuing to read this page, you have two options: +====== Using git ======
-  - If you are happy with using svn, stop reading here. +
-  - If you would like to experiment with git, continue reading.+
  
-This page has been benefited lot from the following pages: +git is general purpose version control system that supports numerous workflows This document discusses three key ways to use git.
-  * [[http://www.viget.com/extend/effectively-using-git-with-subversion/|Effectively Using Git With Subversion]]+
  
-=====Installing git=====+  * Testing Workflow - For testers who won't be making changes. 
 +  * Developer Workflow (Simiplified) - If you will be making changes. 
 +  * Branching Workflow - More advanced git usage for developers.
  
-Install first git and a graphical client (e.g. gitk) for it +If you want to go even deeper into git, the git book will take you there:
-<code> +
-sudo apt-get install git gitk +
-</code>+
  
-=====Applying git clone to the svn repository===== +  https://git-scm.com/book/en/v2
-Create the following ''git-clone-rg-repository.sh'' script in order to clone the repository +
-<code> +
-#!/bin/bash +
-USERNAME=<username> +
-ERROR_CODE=-1 +
-while [ $ERROR_CODE -ne 0 ]; do +
-  # repeat until final success +
-  git svn clone -s https://${USERNAME}@rosegarden.svn.sourceforge.net/svnroot/rosegarden rosegarden.git +
-  # it may be possible that the commands ends to an error like 'RA layer request failed:' +
-  let ERROR_CODE=$? +
-  # just a small pause before repeating the command +
-  sleep 1 +
-done +
-echo Finished. +
-</code> +
-The clone the repository (takes a long, long time (several, or, even tens of hours) and 662 Mb to fetch all branches) by running the script +
-<code> +
-bash ./git-clone-rg-repository.sh +
-</code> +
-If the script still fails, end the loop by pressing Ctrl+C and rerun the script.+
  
-=====Example commit 1: Generating .gitignore and adding it to the subversion repository===== +===== Testing Workflow =====
-(These lines have already been executed once.)+
  
-==== Generating .gitignore ====+If you don't plan on submitting code changes, you can track development using just a few git commands.
  
-Generate the ignore file with +First, you'll want to make a clone of the git repo on your local machine This is similar to "svn checkout".
-<code> +
-cd rosegarden.git +
-git-svn show-ignore > .gitignore +
-</code>+
  
-==== Adding file to a following local commit ====+  git clone git://git.code.sf.net/p/rosegarden/git rosegarden-git
  
-Add the generated file to the local commit +That will create a rosegarden-git directory where you can build and test as usual.
-<code> +
-git add .gitignore +
-</code> +
-and check the status of the repository, if you wish +
-<code> +
-git status +
-</code> +
-the following lines will result +
-<code> +
-# On branch master                                          +
-# Changes to be committed:                                  +
-#   (use "git reset HEAD <file>..." to unstage)             +
-#                                                           +
-#       new file:   .gitignore                              +
-#     +
-</code>+
  
-==== Committing locally ====+If you want to get the latest, you can fetch and rebase.  This is similar to "svn update".
  
-Commit locally the changes +  git fetch --tags 
-<code> +  git rebase
-git commit .gitignore +
-</code> +
-write then the comment +
-<code> +
-Add .gitignore file as a result of the following command: +
- git svn show-ignore > .gitignore +
-</code> +
-after writing the comment, save the file in editor and finally quit the editor. +
-This will commit locally the changes and the following information will be given +
-<code> +
-Created commit 4dcfaa7: Add .gitignore file as a result of the following command: +
- 1 files changed, 181 insertions(+), 0 deletions(-)                               +
- create mode 100644 .gitignore                                                    +
-</code>+
  
-==== Fetching latest changes before commit ====+To examine your local copy of the history, use git log.
  
-Before committing, you want make sure that you have the latest version of the source +  git log
-<code> +
-git svn rebase +
-</code> +
-Invoking the above command +
-  - reverts temporarily the changes you have made +
-  - downloads all changes from subversion,  +
-  - applies the downloaded changes from subversion to the previous version downloaded from subversion, and +
-  - applies again the changes you have made. +
-The following lines will be printed +
-<code> +
-First, rewinding head to replay your work on top of it...                         +
-Applying: Add .gitignore file as a result of the following command:               +
-</code>+
  
-==== Committing back to subversion ====+Or even nicer is the gitk GUI.
  
-Suggesting that there were no code to merge and no conflicts to solve, you can then commit back to subversion +  gitk &
-<code> +
-git svn dcommit +
-</code> +
-You will see then the following output +
-<code> +
-Committing to https://hjunes@rosegarden.svn.sourceforge.net/svnroot/rosegarden/trunk ... +
-        A       .gitignore                                                               +
-Committed r10792                                                                         +
-        A       .gitignore                                                               +
-r10792 = 8d3f93067b542f7e770c08a3e84c8fb4bb8fb46f (trunk)                                +
-No changes between current HEAD and refs/remotes/trunk                                   +
-Resetting to the latest refs/remotes/trunk                                               +
-</code> +
-As you can see, the commit has been assigned subversion's version number 10792.+
  
-===== A typical short working cycle =====+And that should be everything you need for testing and using the latest.  Questions are always welcome on the users mailing list.
  
-First you check for new updates +===== Developer Workflow (Simplified) =====
-<code> +
-git svn rebase +
-</code>+
  
-Then you make your changes, compile and test +The simplest way to work with git as a developer is to avoid branches and commit changes directly to your master branch.
-<code> +
-[... editing ...] +
-make +
-./rosegarden +
-</code>+
  
-Now lets prepare for the commit. First lets see what changes we are going to commit +To get started, you'll need to fork the repo you want to work on.  This makes a public copy that can only be modified by you.  In sourceforge, click the "fork" link in the left column of the code viewer.
-<code+
-git diff +
-</code>+
  
-Add files which were changed and commit them locally +  https://sourceforge.net/p/rosegarden/git/ci/master/tree/
-<code> +
-git add [file1 file2 ...] +
-git commit -m "Message..." +
-</code>+
  
-Then one more check for probable new set of changes +It will allow you to set the home project (use the default which is your sourceforge userid), the label (this is the unique name that appears in your profile), and the mount point (the name in the URL it creates).  Just go with defaults for your first fork.  Usually, defaults will be fine.
-<code> +
-git svn rebase +
-</code> +
-No merge was needed in this example.+
  
-Finally, submit the changes +The fork will take a while.  It is making a copy of the entire 150+MB rosegarden repo for your personal use on the sourceforge servers.  Then it is analyzing that copy which takes a minute or so.
-<code> +
-git svn dcommit +
-</code>+
  
-That was it. The above set of commands is not optimalbut it works.+Wait a few moments and do a refresh and the repo should appear.  Now you can clone it using "ssh" protocol so you can write (push) to it.  Use the command that appears in the "Read/Write SSH access" box to do your clone.  It will look something like this: 
 + 
 +  git clone ssh://tedfelix@git.code.sf.net/u/tedfelix/rosegarden tedfelix-rosegarden 
 + 
 +That will create a "tedfelix-rosegarden" directory that we can build and test from.  And since this will be connected to your fork, you can make changes and push them as well. 
 + 
 +As with svn, you can use "git status" to see what you have changed. 
 + 
 +<file> 
 +$ git status 
 +On branch master 
 +Your branch is up to date with 'origin/master'
 + 
 +Changes not staged for commit: 
 +  (use "git add <file>..." to update what will be committed) 
 +  (use "git restore <file>..." to discard changes in working directory) 
 + modified:   README 
 + 
 +no changes added to commit (use "git add" and/or "git commit -a") 
 +</file> 
 + 
 +git diff provides all the details. 
 + 
 +<file> 
 +$ git diff 
 +diff --git a/README b/README 
 +index b17b6c4a5..f93535a00 100644 
 +--- a/README 
 ++++ b/README 
 +@@ -139,7 +139,7 @@ data/appdata.  It is named rosegarden.appdata-old.xml. 
 + Authors and copyright 
 + --------------------- 
 +  
 +-Rosegarden is Copyright 2000-2020 The Rosegarden Development Team 
 ++Rosegarden is Copyright 2000-2021 The Rosegarden Development Team 
 +  
 + See http://rosegardenmusic.com/resources/authors/ for a complete list of 
 + developers past and present, and to learn something about the history of our 
 +</file> 
 + 
 +Or get a summary with "--stat"
 + 
 +<file> 
 +$ git diff --stat 
 + README | 2 +- 
 + 1 file changed, 1 insertion(+), 1 deletion(-) 
 +</file> 
 + 
 +When you are ready to commit, use git add/rm and git commit. 
 + 
 +<file> 
 +$ git add . 
 +$ git status 
 +On branch master 
 +Your branch is up to date with 'origin/master'
 + 
 +Changes to be committed: 
 +  (use "git restore --staged <file>..." to unstage) 
 + modified:   README 
 + 
 +$ git commit 
 +[master b142e48bd] Update README 
 + 1 file changed, 1 insertion(+), 1 deletion(-) 
 +</file> 
 + 
 +https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository 
 + 
 +To stay up to date, first make sure your working copy is clean.  If it isn't, either commit your changes or stash them. 
 + 
 +  git status   
 + 
 +Then you can fetch the latest changes and rebase your changes on them. 
 + 
 +  git fetch --tags 
 +  git rebase 
 + 
 +If you stashed changes, you can pop the stash now to get them back. 
 + 
 +  git stash pop 
 + 
 +Once your changes are ready to be incorporated into the project, push them to your remote fork on sourceforge (origin). 
 + 
 +  git push 
 + 
 +And then send a merge request to the owner of the original repo that you forked.  On the sourceforge website, click on the "Request Merge" link in the left column in sourceforge's code viewer.  Then fill in the summary and an optional description.  Source and target branch will be "master"
 + 
 +The owner of the original repo will then get the merge request and decide what to do with it. 
 + 
 +===== Branching Workflow ===== 
 + 
 +Creating a new branch is as simple as a checkout with the -b option.  In this case we create a new branch based on master: 
 + 
 +  $ git checkout -b newbranch master 
 +  Switched to a new branch 'newbranch' 
 + 
 +You can commit to this new branch just like you would with any other branch like master.  Before you start workingthough, make sure you are in the right branch with git status. 
 + 
 +  $ git status 
 +  On branch newbranch 
 +  nothing to commit, working tree clean 
 + 
 +Switching branches is also a checkout. 
 + 
 +  $ git checkout master 
 +  Switched to branch 'master' 
 +  Your branch is up to date with 'origin/master'
 +  $ git checkout newbranch 
 +  Switched to branch 'newbranch' 
 + 
 +You can list your local branches. 
 + 
 +<file> 
 +$ git branch -v 
 +  master    b142e48bd Update README 
 +* newbranch b142e48bd Update README 
 +</file> 
 + 
 +And examine your remote branches. 
 + 
 +<file> 
 +$ git remote show origin 
 +* remote origin 
 +  Fetch URL: ssh://tedfelix@git.code.sf.net/u/tedfelix/rosegarden 
 +  Push  URL: ssh://tedfelix@git.code.sf.net/u/tedfelix/rosegarden 
 +  HEAD branch: master 
 +  Remote branch: 
 +    master tracked 
 +  Local branch configured for 'git pull': 
 +    master merges with remote master 
 +  Local ref configured for 'git push': 
 +    master pushes to master (up to date) 
 +</file> 
 + 
 +To push a new branch to your remote fork on sourceforge (origin) be sure to specify the "upstream" with the "-u" option: 
 + 
 +<file> 
 +$ git checkout newbranch 
 +Switched to branch 'newbranch' 
 +$ git push -u origin newbranch 
 +Total 0 (delta 0), reused 0 (delta 0) 
 +remote: <Repository /git/u/tedfelix/rosegarden.git> refresh queued. 
 +To ssh://git.code.sf.net/u/tedfelix/rosegarden 
 + * [new branch]          newbranch -> newbranch 
 +Branch 'newbranch' set up to track remote branch 'newbranch' from 'origin'
 +</file> 
 + 
 +After the upstream is set, you can simply say "git push" and git will remember. 
 + 
 +  git push 
 + 
 +While working with branches, don't forget to periodically fetch the latest changes to master. 
 + 
 +  git checkout master 
 +  git fetch --tags 
 +  git rebase 
 + 
 +To delete a branch from your remote fork on sourceforge (origin): 
 + 
 +<file> 
 +$ git push origin --delete newbranch 
 +remote: <Repository /git/u/tedfelix/rosegarden.git> refresh queued. 
 +To ssh://git.code.sf.net/u/tedfelix/rosegarden 
 + - [deleted]             newbranch 
 +</file> 
 + 
 +To delete a local branch: 
 + 
 +  $ git branch -d newbranch 
 +  Deleted branch newbranch (was b142e48bd). 
 + 
 +Depending on whether it thinks commits may be lost, git might require you to specify "-D" to force the delete. 
 + 
 +And finally, if you're about to go through some scary git commands on a branch, you can always drop a safety branch that you can get back to at any time. 
 + 
 +  git branch my-safety-branch1 
 +  ... (lots of scary git commands like git reset and git pull) 
 +  git checkout my-safety-branch1
  
  
 
 
dev/using_git.txt · Last modified: 2022/05/06 16:07 (external edit)
Recent changes RSS feed Creative Commons License Valid XHTML 1.0 Valid CSS Driven by DokuWiki