From Amarok Wiki
Git can be used for feature branches, since SVN is so bad at branching. Thanks to Ian[1] for the initial git information and for being the resident Git expert.
Contents |
Initial Setup
User Config
Set your email for commit messages.
git config user.email johndoe@example.com
Set your name for commit messages.
git config user.name 'John Doe'
Getting Amarok
We just moved the sources to http://gitorious.org/amarok (as of Monday, July 20, 2009). To obtain git, just type:
git clone git://gitorious.org/amarok/amarok.git
For further info, also see 2.0_Development_HowTo.
Day-to-day stuff
After you edit
git diff # to see the changes made git commit -a # the -a means include all modified/new files in the commit # you can selectively commit modified files by using 'git add filename'
If you have made a bunch of changes and want to commit, but don't want to commit all the changes you've made run
git add --interactive # or git add --patch
# When you are ready to push all your git commits to the svn git svn dcommit
upstream has some new stuff
git pull --rebase git log
Branching
Compared to SVN, git's branching features are extremely powerful. If are planning to make some complicated changes to the source code, you can easily create a private branch, track your changes in the branch, and get the changes working before committing the whole thing to the main Amarok SVN repository.
By default, git starts off with 1 branch called "master." To create a private branch off of this:
git checkout -b MYBRANCH
To see the current branch:
git branch
To switch back and forth between branches:
git checkout master git checkout MYBRANCH
To update your private branch to the latest SVN sources:
git checkout master git svn rebase git checkout MYBRANCH git rebase master
During the "rebase master" step, you may need to resolve conflicts using repeated applications of "git mergetool" and "git rebase --continue" to bring your branch fully up to date. See the git-rebase documentation for more information.
To commit changes in a branch to the main SVN repository, your should first update your private branch to the latest SVN sources (see the section above). Then you can merge the private branch into the master branch and commit it to the SVN repository:
git checkout master git merge --squash MYBRANCH # so as to generate 1 svn commit, not 1 for each git commit git commit git svn dcommit
After you've merged the changes from a branch into the master, you can delete the branch:
git branch -D MYBRANCH
If you want to keep using the branch after merging its changes into the master, the easiest thing to do is to delete it and recreate it. If you don't want to do that, you can run:
git checkout MYBRANCH git rebase master git rebase --skip # repeat until MYBRANCH is up to date
Conflicts
Work through conflicted files by opening them in your mergetool (opendiff, kdiff3, etc.) and choosing left/right chunks. The merged result is staged for commit.
git mergetool
For binary files or if mergetool won't do, resolve the conflict(s) manually and then do:
git add <file1> [<file2> ...]
Once all conflicts are resolved and staged, commit the pending merge with:
git commit
Tricks n Tips
SVN Rebase with Outstanding Edits: git stash
You are in the middle of something, and you learn that there are SVN changes that are possibly relevant to what you are doing. If you try and git svn rebase with outstanding edits git refuses. In such a case, you can stash your changes away, perform a pull, and then unstash, like this:
$ git svn rebase src/some/file.h: needs update $ git stash # stashes all edits away, all edits are reverted. $ git svn rebase $ git stash apply # Continue Working.
git stash Overview:
git stash list # lists all stashes you have made
git stash apply stash@{NUMBER} # applies the stash with: stash@{NUMBER}, defaults to 0
git stash show stash@{NUMBER} # shows what exactly is in a stash
git stash clear # clears all stashed states (be careful!)
git stash drop stash@{NUMBER} # removes stash@{NUMBER}
Oh Shit: Undo
You've made some changes to a file(s) and you've decided you want to scrap all the work.
git checkout /path/to/file
Abandon everything since your last commit. This command can be DANGEROUS. If merging has resulted in conflicts and you'd like to just forget about the merge use this command.
git reset --hard
Undo your most recent successful merge and any changes that occurred after. Useful for forgetting about the merge you just did. If there are conflicts (the merge was not successful), use "git reset --hard" (above) instead.
git reset --hard ORIG_HEAD
Undo your last commit
git reset --soft HEAD^
You committed something to svn but now you want to take it back:
git log # grab the commit hash you want to revert git revert <commit hash> git svn dcommit
Ignoring Files/Directories
There are certain folders/files which may not require tracking, and git will say on every checkout and status what these files are, which can be a nuisance.
Solution:
- Goto
./amarok/.git/info/exclude./amarok/.gitignore - Add directories/files desired to be ignored. Wildcards are OK (and encouraged).
Example exclude:
/src/context/animators /src/context/plasma /Doxyfile /src/amarok-build
Ramblurr's .gitignore
*~ src/context/animators /src/context/plasma *.kdev* .gitignore tags Doxyfile *#*# .#*
Colorize Output
Treat yourself to some color. Add the following to ~/.gitconfig
[color] branch = auto diff = auto status = auto [color "branch"] current = yellow reverse local = yellow remote = green [color "diff"] meta = yellow bold frag = magenta bold old = red bold new = green bold [color "status"] added = yellow changed = green untracked = cyan