Difference between revisions of "Basic Git usage"

From MultimediaWiki
Jump to navigation Jump to search
Line 20: Line 20:
  git-checkout <name of branch>
  git-checkout <name of branch>


Delete a branch (keeping the history):
Delete a branch (must be merged with HEAD of current branch, keeping the history):
  git-branch -d <name of branch>
  git-branch -d <name of branch>


Delete a branch (<b>removing</d> the history):
Delete a branch (irrespective of merge status, <b>removing</b> the history):
  git-branch -D <name of branch>
  git-branch -D <name of branch>



Revision as of 07:13, 28 January 2008

Fundamentals

Initial checkout:

git-clone git://git.mplayerhq.hu/ffmpeg ffmpeg-git

And if you want libswscale as well:

cd ffmpeg-git
git-clone git://git.mplayerhq.hu/libswscale

Update (this has to be done in ffmpeg-git and in its libswscale subdir as they are currently separate repositories):

git-pull

Make some changes, revert to a particular commit on the master branch:

git-reset --hard <commit>

Make a branch:

git-branch <name of branch>

Switch to a branch (make it the active branch such that source files reflect the source in that branch):

git-checkout <name of branch>

Delete a branch (must be merged with HEAD of current branch, keeping the history):

git-branch -d <name of branch>

Delete a branch (irrespective of merge status, removing the history):

git-branch -D <name of branch>

Guis and helper scripts

http://wiki.multimedia.cx/index.php?title=Git_Guis

git-*.sh at http://www1.mplayerhq.hu/~reimar/

Working on a series of incremental, dependent patches

Edit some files making functional changes. Commit changes locally - prompted for a commit message using $EDITOR to write it

git-commit -a

Edit some files making cosmetic changes and commit again.

git-commit -a

Prepare patches for e-mail submission (this creates the patches numbered and in order for easy submission):

git-format-patch origin

Generate a diff of branch 2 against branch 1 (i.e. branch 1 + patch = branch 2)

git-diff <name of branch 1> <name of branch 2>

Apply a git-diff style patch in a working Git tree:

git-am foo.patch

Apply a git-diff style patch in any working directory containing the correct source files to be patched:

git-apply foo.patch

(Note: git-am will create a new commit using the extra metadata for the commit message, etc. whereas git-apply just patches the files)

Revert the last n (where n is a positive int) commits from the active branch:

git-reset --hard HEAD~n

get a hack out of the way

You probably need a fairly new version of git for this feature.

To quickly get rid of some local, non-committed changes:

git-stash

To get them back again:

git-stash apply

WANTED

(Note: When using the following method, I wholly expect it uses the $EDITOR environment variable so make sure it's set to your text editor of choice.)

When submitting a set of patches to be applied in order, it is common to want to go back and edit one of the intermediate commits depending on feedback for the patches. This process can be easily achieved using the marvellous git-rebase:

git-rebase -i <commit preceding the ones in which interested>

This will display a list of the commits from the one after that specified and HEAD and gives you the opportunity to remove commits, reorder them, edit them and 'squash' a commit into the one preceding it. When you've edited this list accordingly you should be presented with those commits that were requested to be edited, or need editing, in order. Cool, huh? :)