Differences

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

Link to this comparison view

Next revision
Previous revision
docs:git:git_walkthrough [2009/11/15 22:11] – created billhdocs:git:git_walkthrough [2012/10/09 14:30] (current) billh
Line 1: Line 1:
 ====== git walkthrough ====== ====== git walkthrough ======
-  * (introduce yourself to git)<code>+  * this page mostly shows command line options; after you are familiar with them, learn how to use the git gui programs too for efficiency: 
 +    * [[.:git gui]] 
 +    * [[.:gitk]] 
 +  * know how to get help first!<code> 
 +git help (general overview) 
 + 
 +git help [command], ie: 
 +  git help init 
 +  git help checkout 
 +  git help branch 
 +  git help status 
 +  git help log 
 +</code> 
 +  * introduce yourself to git; this sets up your [[.:gitconfig]] file<code>
 git config --global user.name "Your Name" git config --global user.name "Your Name"
 git config --global user.email "youremail@example.com" git config --global user.email "youremail@example.com"
 </code> </code>
-  * start with an existing project (export one from svn if you want)+  * start with an existing set of source code files to play with
   * cd inside the project root, then create a repository:<code>   * cd inside the project root, then create a repository:<code>
 git init git init
 </code> </code>
-  * (notice that a .git directory will be created at project root)+  * :!: (notice that a .git directory will be created at project root) 
 +    * git is cool - the complete repository (all history) is stored inside this .git directory 
 +    * even if you clone a repository from someone else, you have the full history available to work with - no further connection with them is required, unless you want future updates or to share code together 
 +  * **IF YOU ARE USING CYGWIN ON WINDOWS...**<code> 
 +git config core.filemode false 
 +</code> 
 +    * this tells git to ignore filemode permissions which do not work correctly on a non-unix host; if you don't do this, git will always complain that you are changing file permissions when you did nothing
   * add all content to the index (some call it the cache, it means what is staged for the next commit)<code>   * add all content to the index (some call it the cache, it means what is staged for the next commit)<code>
 git add . git add .
Line 15: Line 34:
 git commit -m "initial import" git commit -m "initial import"
 </code> </code>
-  * (modify some files)+  * (modify some files, but don't add any new ones)
   * commit the changes<code>   * commit the changes<code>
 git commit -a git commit -a
  
-(the -a switch will tell git to add and commit all changed files)+the -a switch will tell git to add and commit all changed files
 +  if any were added, you would need to do git add for those 
 + 
 +* when the -m switch is used, you specify the commit message here 
 +  on the command line; when it is ommitted, your default editor 
 +  (probably vimwill open
 </code> </code>
   * create an experimental branch<code>   * create an experimental branch<code>
Line 29: Line 53:
   * switch to the experimental branch<code>   * switch to the experimental branch<code>
 git checkout experimental git checkout experimental
 +
 +* the shorthand way to create a branch and check it out at the same time is:
 +git checkout -b experimental
 +
 +* you can also give a different reference to start the new branch at:
 +git checkout -b experimental HEAD~4
 +or
 +git checkout -b experimental e8f2ab
 +or
 +git checkout -b experimental sometagname
 </code> </code>
   * show branches again, with the * on experimental, indicating the current branch<code>   * show branches again, with the * on experimental, indicating the current branch<code>
Line 53: Line 87:
   * note that git will allow you to commit the files with conflicts in them!   * note that git will allow you to commit the files with conflicts in them!
   * once the conflicts are resolved, commit the merge with git commit -a   * once the conflicts are resolved, commit the merge with git commit -a
 +    * if you know that one version of the file is fully correct and doesn't need manually fixed, you can do this to update the file and tell git the file conflict is resolved<code>
 +git checkout --ours somefile
 +or
 +git checkout --theirs somefile
 +
 +* --ours represents the file on our branch before the merge
 +* --theirs represents the file on the branch we are merging into ours
 +</code>
   * (modify one file)   * (modify one file)
   * view diff of changes<code>   * view diff of changes<code>
 git diff git diff
 +</code>
 +  * if you have already staged some changes, git diff will not show them.  To see what the diff is with the staged changes, you need to do this:<code>
 +git diff --cached
 </code> </code>
   * contrary to svn, where we would run svn revert <filename>, when using git we use git checkout <filename or path> to restore the last commited state of a file, and lose any working copy changes   * contrary to svn, where we would run svn revert <filename>, when using git we use git checkout <filename or path> to restore the last commited state of a file, and lose any working copy changes
Line 63: Line 108:
 </code> </code>
   * to "go back in time" and review a project at the point of a previous commit, you can do so by creating a branch at that point and then checking it out<code>   * to "go back in time" and review a project at the point of a previous commit, you can do so by creating a branch at that point and then checking it out<code>
-git branch old 53067 +git checkout -b old 53067
-git checkout 53067+
  
 (when finished, delete the branch) (when finished, delete the branch)
  • docs/git/git_walkthrough.1258348272.txt.gz
  • Last modified: 2009/11/15 22:11
  • by billh