TubeTK/Development/GITCheatSheet: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
(Blanked the page)
 
(18 intermediate revisions by 3 users not shown)
Line 1: Line 1:
= Workspace tips =
* Show branch in prompt
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[01;33m\]`git branch 2>/dev/null|cut -f2 -d\* -s|sed -e"s/ //g"`\[\033[00m\]\$ '
* gitk is a great tool for visualizing the git history and seeing where your master or branch is wrt origin:master
gitk


= Maintain a linear git history =
== Helpful scripts ==
* http://www.dinnermint.org/tutorial/dead-simple-git-workflow-for-agile-teams
=== gitupdate ===
#!/bin/sh -x
# hack: Merge the latest changes from the master branch into your current branch
ref=$(git symbolic-ref HEAD 2> /dev/null) || exit 0
CURRENT="${ref#refs/heads/}"
git checkout master
git pull origin master
git checkout ${CURRENT}
git rebase master
=== gitship ===
#!/bin/sh -x
# Git workflow ship script from: http://reinh.com/blog/2008/08/27/hack-and-and-ship.html
# git name-rev is fail
ref=$(git symbolic-ref HEAD 2> /dev/null) || exit 0
CURRENT="${ref#refs/heads/}"
git checkout master
git merge ${CURRENT}
git push origin master
git checkout ${CURRENT}
== Workflow recommendation ==
We recommend the scripts described above.  They implement the following, and save you much typing and potential errors!  Most importantly, do your work in branches, not in master!
# Keep a local master branch which only is a pointer to the gitorious master (does not contain local changes)
# Make development modification in a local branch
# When getting ready to push these changes to the origin try the following
## Do a git pull on master to fetch and merge all changes from gitorious
### '''git checkout master'''
### '''git pull origin master'''
## Do a git rebase of the topic branch onto master - That is with topic checkout do "git rebase master"
### '''git rebase master topic'''
## Fix any conflicts that result
### Edit files
### '''git add -u'''
### '''git rebase --continue'''
## Merge the topic branch - This will result in an fast-forward merge.
### '''git merge topic'''
## git push your local master branch
### '''git push origin master'''
=== Create a checkout ===
* git clone git://gitorious.org/tubetk/tubetk.git
=== Stash local changes temporarily ===
* git stash
=== Create a local branch ===
* git branch test
=== Swtich to a local branch ===
* git checkout test
=== Get stashed local changes ===
* git stash pop
=== Update a branch to the remote master's head ===
* git stash
* git rebase origin master
* git stash pop
=== Add to local commit ===
* git add <filename>
* git add -A
=== Push local commit ===
* git push origin master
=== Remove a local branch ===
* git checkout master
* git branch -d <branch>
=== Track a remote branch ===
* "git fetch" (get up to date) or "git pull"
* git branch --track somebranch origin/somebranch
** --track is not needed unless you've set branch.autosetupmerge to false in your config
* git checkout somebranch
* git commit
* git push
** sends changes to origin/somebranch
=== Delete a remote branch ===
* Don't do this unless you're incredibly confident in what you're doing
* git push origin :somebranch
=== Project History ===
* git log        ( To view the history of your changes )
* git log -p    ( To see complete diffs at each step )
* git log --stat --summary  ( To see overview  )
=== Setting up tracked repositories to start pushing ===
#If you have cloned read-only version, do the following first
## git remote rm origin
# Add the proper remote
##git remote add origin git@gitorious.org:tubetk/tubetk.git
# You can push your changes
##git push origin master
git://gitorious.org/tubetk/tubetk.git
=== Use a global ignore file for editor backups ===
Different developers' editors use different backup file names. Rather than put every possible editor backup file name in every project .gitignore, use a personal gitignore file to ignore your own editor backup files:
git config --global core.excludesfile ~/.gitignore
echo '*~' >> ~/.gitignore
Now, the exclusion pattern '*~' will be applied in every directory of every git project you use.
=== View history ===
Take a look at the history:
git log -C --stat
(git log has a bunch of options; this set detects renames and copies, and shows a summary of what files are changed in each commit)
Get a closer look at a particular change by commit:
git log -C -p -1 57c609
(-p shows a patch, -1 restricts to a single change, and 57c609 is the start of a commit shown by the first 'git log' command)
Get a list of commits to a particular file since vBeta branch:
git log --oneline vBeta..origin/v1.0 -- CMakeLists.txt
View history graphically, if you installed the necessary program:
gitk --all
qgit --all
You can also [view the history online in gitorious/github], but viewing the history locally is often more powerful.
= Additional References =
* GIT tutorial [http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html]
* GIT guide from gitorious [http://qt.gitorious.org/qt-jambi/pages/GitGuide]
* GIT guide in CMake [http://www.cmake.org/Wiki/CMake/Git]
* GIT quick reference [http://jonas.nitro.dk/git/quick-reference.html]

Latest revision as of 15:15, 26 July 2013