Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Notes about Git

, 4 Jan 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
These are my notes about git for use as quick reference. Fundamentals Typically a version control system has a repository where it stores the history of all changes. Then there’s your local development directory where you checkout a copy of the repositories contents, do some edits and then com

These are my notes about git for use as quick reference.

Fundamentals

Typically a version control system has a repository where it stores the history of all changes. Then there’s your local development directory where you checkout a copy of the repositories contents, do some edits and then commit them back to the repository. Git breaks this model and adds an intermediate stage called the index that sits between your working directory and the git repository. Changes make there way from the working tree to the index then to the repository.

Checking out a svn hosted repository

You can use git with a svn repository. Note that this step can take a few hours because git checkouts out every revision in the svn repository and commits it locally.

git svn clone http://llvm.org/svn/llvm-project/libcxx/trunk libcxx

Updating your sources

git svn rebase

Updating your sources after editing

sashan@cyclops clang master $ git svn rebase
include/clang/AST/Stmt.h: needs update
lib/AST/Stmt.cpp: needs update
update-index --refresh: command returned error: 1

Oops … git’s complaining that you have edited files in the working tree. Use git stash to save the changes locally.

sashan@cyclops clang master 1 $ git stash
Saved working directory and index state WIP on master: 3923c27 Fix diagnostic reporting of previous default statements.
HEAD is now at 3923c27 Fix diagnostic reporting of previous default statements.

Now you can rebase.

sashan@cyclops clang master $ git svn rebase
        M       docs/UsersManual.html
r121768 = 024394010048e704192f4f34f21836a550f37a9f (refs/remotes/git-svn)

And then apply the stashed changes

sashan@cyclops clang master 1 $ git stash pop

Committing changes in the working tree directly to the repository

This will add all editted files to index and then to repository. It will also prompt you to enter a commit log message. The -a parameter tells git to add all edited files.

sashan@cyclops clang master $ git commit -a

Selecting the files to commit

This stages files for committing adding them to the index.

sashan@cyclops clang master $ git add <file name>

After this you should run git commit to commit the files.

Generating a patch for email submission

This will generate a patch file of the most recent commit that you can email as an attachment.

sashan@cyclops clang master $ git format-patch -1 -p
0001-Fix-diagnostic-reporting-of-previous-default-stateme.patch

Adding edited files to the index

Sometimes you want to add changes in the working tree to the index without committing to the repository at the same time. In this case doing a git commit -a won’t help. You need to use git add. The example below shows a session using git add -ui. The -u is for update and means that only modified paths in the working tree will be added to the index. New paths won’t. The -i is for interactive and therefore git will prompt you for a response. In the session below I enter interactive mode, choose to update the index, and then select a range of paths, 1 to 7, to update the index with. Importantly, after finishing the update I hit enter to exit the interactive update mode.

sashan@cyclops clang use_std_set_for_switch_cases $ git add -ui
           staged     unstaged path
  1:    unchanged      +51/-31 include/clang/AST/Stmt.h
  2:    unchanged        +6/-1 lib/AST/Stmt.cpp
  3:    unchanged        +4/-4 lib/Sema/JumpDiagnostics.cpp
  4:    unchanged        +5/-3 lib/Sema/SemaCodeComplete.cpp
  5:    unchanged       +14/-6 lib/Sema/SemaStmt.cpp
  6:    unchanged        +8/-2 lib/Serialization/ASTReaderStmt.cpp
  7:    unchanged        +3/-3 lib/Serialization/ASTWriterStmt.cpp

*** Commands ***
  1: status       2: update       3: revert       4: add untracked
  5: patch        6: diff         7: quit         8: help
What now> 2
           staged     unstaged path
  1:    unchanged      +51/-31 include/clang/AST/Stmt.h
  2:    unchanged        +6/-1 lib/AST/Stmt.cpp
  3:    unchanged        +4/-4 lib/Sema/JumpDiagnostics.cpp
  4:    unchanged        +5/-3 lib/Sema/SemaCodeComplete.cpp
  5:    unchanged       +14/-6 lib/Sema/SemaStmt.cpp
  6:    unchanged        +8/-2 lib/Serialization/ASTReaderStmt.cpp
  7:    unchanged        +3/-3 lib/Serialization/ASTWriterStmt.cpp
Update>> 1-7
           staged     unstaged path
* 1:    unchanged      +51/-31 include/clang/AST/Stmt.h
* 2:    unchanged        +6/-1 lib/AST/Stmt.cpp
* 3:    unchanged        +4/-4 lib/Sema/JumpDiagnostics.cpp
* 4:    unchanged        +5/-3 lib/Sema/SemaCodeComplete.cpp
* 5:    unchanged       +14/-6 lib/Sema/SemaStmt.cpp
* 6:    unchanged        +8/-2 lib/Serialization/ASTReaderStmt.cpp
* 7:    unchanged        +3/-3 lib/Serialization/ASTWriterStmt.cpp
Update>>
updated 7 paths

*** Commands ***
  1: status       2: update       3: revert       4: add untracked
  5: patch        6: diff         7: quit         8: help
What now> 7
Bye.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

sashan govender

Australia Australia
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 4 Jan 2011
Article Copyright 2011 by sashan govender
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid