1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-08-05 06:17:36 +02:00

Fixed stuff

This commit is contained in:
Adam
2013-07-21 16:47:55 -07:00
parent c914885188
commit 1466127aa3
3 changed files with 347 additions and 409 deletions

View File

@@ -1,8 +1,8 @@
--- ---
category: tool
language: git tool: git
contributors: contributors:
- ["Jake Prather", "http://github.com/JakeHP"] - ["Jake Prather", "http:#github.com/JakeHP"]
filename: LearnGit.txt filename: LearnGit.txt
--- ---
@@ -16,419 +16,357 @@ manage your source code.
In layman's terms, it's a way of managing, and keeping a detailed historical record, In layman's terms, it's a way of managing, and keeping a detailed historical record,
of your source code. of your source code.
## Versioning Concepts
### What is version control?
Version control is a system that records changes to a file, or set of files, over time.
### Centralized Versioning VS Distributed Versioning
* Centralized version control focuses on synchronizing, tracking, and backing up files.
* Distributed version control focuses on sharing changes. Every change has a unique id.
* Distributed systems have no defined structure. You could easily have a SVN style, centralized system, with git.
[Additional Information](http:#git-scm.com/book/en/Getting-Started-About-Version-Control)
### Why Use Git?
* Can work offline.
* Collaborating with others is easy!
* Branching is easy!
* Merging is easy!
* Git is fast.
* Git is flexible.
## Git Architecture
### Repository
A set of files, directories, historical records, commits, and heads. Imagine it as a source code datastructure,
with the attribute that each source code "element" gives you access to its revision history, among other things.
A git repository is comprised of the .git directory & working tree.
### .git Directory (component of repository)
The .git directory contains all the configurations, logs, branches, HEAD, and more.
[Detailed List.](http:#gitready.com/advanced/2009/03/23/whats-inside-your-git-directory.html)
### Working Tree (component of repository)
This is basically the directories and files in your repository. It is often referred to
as your working directory.
### Index (component of .git dir)
The Index is the staging area in git. It's basically layer that separates your working tree
from the Git repository. This gives developers more power over what gets sent to the Git
repository.
### Commit
A git commit is a snapshot of a set of changes, or manipulations to your Working Tree.
For example, if you added 5 files, and removed 2 others, these changes will be contained
in a commit (or snapshot). This commit, can then be pushed to other repositorys, or not!
### Branch
A branch is essentially a pointer, that points to the last commit you made. As you commit
this pointer will automatically update and point to the latest commit.
### HEAD and head (component of .git dir)
HEAD, is a pointer, that points to the current branch. A repository only has 1 *active* HEAD.
head, is a pointer, that points to any commit. A repository can have any number of heads.
### Conceptual Resources
[Git For Computer Scientists](http:#eagain.net/articles/git-for-computer-scientists/)
[Git For Designers](http:#hoth.entp.com/output/git_for_designers.html)
## Commands
### init
Create an empty Git repository. The Git repository's settings, stored information,
and more is stored in a directory, or folder named, ".git".
```bash
$ git init
``` ```
/////////////////////////////////////// ### config
// Versioning Concepts
///////////////////////////////////////
/////////////////////////////////////// To configure settings. Whether it be for the repository, the system itself, or global
// What is version control? configurations.
///////////////////////////////////////
Version control is a system that records changes to a file, or set of files, over time.
/////////////////////////////////////// ```bash
// Centralized Versioning VS Distributed Versioning # Print & Set Some Basic Config Variables (Global)
/////////////////////////////////////// $ git config --global user.email
$ git config --global user.name
* Centralized version control focuses on synchronizing, tracking, and backing up files. $ git config --global user.email "MyEmail@Zoho.com"
* Distributed version control focuses on sharing changes. Every change has a unique id. $ git config --global user.name "My Name"
* Distributed systems have no defined structure. You could easily have a SVN style, centralized system, with git. ```
[Additional Information](http://git-scm.com/book/en/Getting-Started-About-Version-Control) [Learn More About git config.](http:#git-scm.com/docs/git-config)
/////////////////////////////////////// ### help
// Why Use Git?
///////////////////////////////////////
* Can work offline. To give you quick access to an extremeled detailed guide of each command. Or to
* Collaborating with others is easy! just give you a quick reminder of some semantics.
* Branching is easy!
* Merging is easy!
* Git is fast.
* Git is flexible.
/////////////////////////////////////// ```bash
// Git Architecture # Quickly check available commands
/////////////////////////////////////// $ git help
/////////////////////////////////////// # Check all available commands
// Repository $ git help -a
///////////////////////////////////////
A set of files, directories, historical records, commits, and heads. Imagine it as a source code datastructure, # Command specific help - user manual
with the attribute that each source code "element" gives you access to its revision history, among other things. # git help <command_here>
$ git help add
$ git help commit
$ git help init
```
A git repository is comprised of the .git directory & working tree. ### status
/////////////////////////////////////// To show differences between the index file (basically your working copy/repo) and the current
// .git Directory (component of repository) HEAD commit.
///////////////////////////////////////
The .git directory contains all the configurations, logs, branches, HEAD, and more.
[Detailed List.](http://gitready.com/advanced/2009/03/23/whats-inside-your-git-directory.html)
/////////////////////////////////////// ```bash
// Working Tree (component of repository) # Will display the branch, untracked files, changes and other differences
/////////////////////////////////////// $ git status
This is basically the directories and files in your repository. It is often referred to # To learn other "tid bits" about git status
as your working directory. $ git help status
```
/////////////////////////////////////// ### add
// Index (component of .git dir)
///////////////////////////////////////
The Index is the staging area in git. It's basically layer that separates your working tree To add files to the current working tree/directory/repo. If you do not git add new files to the
from the Git repository. This gives developers more power over what gets sent to the Git working tree/directory they will not be included in commits!
repository.
/////////////////////////////////////// ```bash
// Commit # add a file in your current working directory
/////////////////////////////////////// $ git add HelloWorld.java
A git commit is a snapshot of a set of changes, or manipulations to your Working Tree. # add a file in a nested dir
For example, if you added 5 files, and removed 2 others, these changes will be contained $ git add /path/to/file/HelloWorld.c
in a commit (or snapshot). This commit, can then be pushed to other repositorys, or not!
/////////////////////////////////////// # Regular Expression support!
// Branch $ git add ./*.java
/////////////////////////////////////// ```
A branch is essentially a pointer, that points to the last commit you made. As you commit ### branch
this pointer will automatically update and point to the latest commit.
/////////////////////////////////////// Manage your branches. You can view, edit, create, delete branches using this command.
// HEAD and head (component of .git dir)
///////////////////////////////////////
HEAD, is a pointer, that points to the current branch. A repository only has 1 *active* HEAD. ```bash
head, is a pointer, that points to any commit. A repository can have any number of heads. # list existing branches & remotes
$ git branch -a
/////////////////////////////////////// # create a new branch
// Conceptual Resources $ git branch myNewBranch
///////////////////////////////////////
[Git For Computer Scientists](http://eagain.net/articles/git-for-computer-scientists/) # delete a branch
[Git For Designers](http://hoth.entp.com/output/git_for_designers.html) $ git branch -d myBranch
# rename a branch
# git branch -m <oldname> <newname>
$ git branch -m myBranchName myNewBranchName
/////////////////////////////////////// # edit a branch's description
// Commands $ git branch myBranchName --edit-description
/////////////////////////////////////// ```
/////////////////////////////////////// ### checkout
// init
///////////////////////////////////////
Purpose: Updates all files in the working tree to match the version in the index, or specified tree.
To create an empty Git repository. The Git repository's settings, stored information,
and more is stored in a directory, or folder named, ".git".
Examples: ```bash
$ git init # Checkout a repo - defaults to master branch
$ git checkout
# Checkout a specified branch
$ git checkout -b branchName
```
/////////////////////////////////////// ### clone
// config
///////////////////////////////////////
Purpose: Clones, or copys, an existing repository into a new directory. It almost adds
To configure settings. Whether it be for the repository, the system itself, or global remote-tracking branches for each branch in the cloned repo. (which allows you to push
configurations. to a remote branch)
Examples: ```bash
# Clone learnxinyminutes-docs
$ git clone https:#github.com/adambard/learnxinyminutes-docs.git
```
// Print & Set Some Basic Config Variables (Global) ### commit
$ git config --global user.email
$ git config --global user.name
$ git config --global user.email "MyEmail@Zoho.com" Stores the current contents of the index in a new "commit". This commit contains
$ git config --global user.name "My Name" the changes made and a message created by the user.
[Learn More About git config.](http://git-scm.com/docs/git-config) ```bash
# commit with a message
$ git commit -m "Added multiplyNumbers() function to HelloWorld.c"
```
/////////////////////////////////////// ### grep
// help
///////////////////////////////////////
Purpose: Allows you to quickly search a repository.
To give you quick access to an extremeled detailed guide of each command. Or to
just give you a quick reminder of some semantics.
Examples: Optional Configurations:
// Quickly check available commands
$ git help
// Check all available commands ```bash
$ git help -a # Thanks to Travis Jeffery for these
# Set line numbers to be shown in grep search results
$ git config --global grep.lineNumber true
// Command specific help - user manual # Make search results more readable, including grouping
// git help <command_here> $ git config --global alias.g "grep --break --heading --line-number"
$ git help add ```
$ git help commit
$ git help init
/////////////////////////////////////// ```bash
// status # Search for "variableName" in all java files
/////////////////////////////////////// $ git grep 'variableName' -- '*.java'
Purpose: # Search for a line that contains "arrayListName" and, "add" or "remove"
To show differences between the index file (basically your working copy/repo) and the current $ git grep -e 'arrayListName' --and \( -e add -e remove \)
HEAD commit. ```
Examples: Google is your friend for more examples
// Will display the branch, untracked files, changes and other differences [Git Grep Ninja](http:#travisjeffery.com/b/2012/02/search-a-git-repo-like-a-ninja)
$ git status
// To learn other "tid bits" about git status ### log
$ git help status
/////////////////////////////////////// Display commits to the repository.
// add
///////////////////////////////////////
Purpose: ```bash
To add files to the current working tree/directory/repo. If you do not git add files to the # Show all commits
working tree/directory they will not be included in commits! $ git log
Exmaples: # Show X number of commits
// add a file in your current working directory $ git log -n 10
$ git add HelloWorld.java
// add a file in a nested dir # Show merge commits only
$ git add /path/to/file/HelloWorld.c $ git log --merges
```
// Regular Expression support! ### merge
$ git add ./*.java
/////////////////////////////////////// "Merge" in changes, from external commits, into the current branch.
// branch
///////////////////////////////////////
Purpose: ```bash
Manage your branches. You can view, edit, create, delete branches using this command. # Merge the specified branch into the current.
$ git merge branchName
Examples: # Always generate a merge commit when merging
// list existing branches & remotes $ git merge --no-ff branchName
$ git branch -a ```
// create a new branch ### mv
$ git branch myNewBranch
// delete a branch Rename or move a file
$ git branch -d myBranch
// rename a branch ```bash
// git branch -m <oldname> <newname> # Renaming a file
$ git branch -m myBranchName myNewBranchName $ git mv HelloWorld.c HelloNewWorld.c
// edit a branch's description # Moving a file
$ git branch myBranchName --edit-description $ git mv HelloWorld.c ./new/path/HelloWorld.c
/////////////////////////////////////// # Force rename or move
// checkout # "existingFile" already exists in the directory, will be overwritten
/////////////////////////////////////// $ git mv -f myFile existingFile
```
Purpose: ### pull
Updates all files in the working tree to match the version in the index, or specified tree.
Examples: Pulls from a repository and merges it with another branch.
// Checkout a repo - defaults to master branch
$ git checkout
// Checkout a specified branch
$ git checkout -b branchName
/////////////////////////////////////// ```bash
// clone # Update your local repo, by merging in new changes
/////////////////////////////////////// # from the remote "origin" and "master" branch.
# git pull <remote> <branch>
$ git pull origin master
```
Purpose: ### push
Clones, or copys, an existing repository into a new directory. It almost adds
remote-tracking branches for each branch in the cloned repo. (which allows you to push
to a remote branch)
Examples: Push, and merge changes from a branch to a remote & branch.
// Clone learnxinyminutes-docs
$ git clone https://github.com/adambard/learnxinyminutes-docs.git
/////////////////////////////////////// ```bash
// commit # Push, and merge changes from a local repo to a
/////////////////////////////////////// # remote named "origin" and "master" branch.
# git push <remote> <branch>
# git push => implicitly defaults to => git push origin master
$ git push origin master
```
Purpose: ### rebase (caution)
Stores the current contents of the index in a new "commit". This commit contains
the changes made and a message created by the user.
Examples: Take all changes that were committed on one branch, and replay them onto another branch.
// commit with a message *Do not rebase commits that you have pushed to a public repo*
$ git commit -m "Added multiplyNumbers() function to HelloWorld.c"
/////////////////////////////////////// ```bash
// grep # Rebase experimentBranch onto master
/////////////////////////////////////// # git rebase <basebranch> <topicbranch>
$ git rebase master oldTest
```
Purpose: [Additional Reading.](http:#git-scm.com/book/en/Git-Branching-Rebasing)
Allows you to quickly search a repository.
Optional Configurations: ### reset (caution)
// Thanks to Travis Jeffery for these
// Set line numbers to be shown in grep search results
$ git config --global grep.lineNumber true
// Make search results more readable, including grouping Reset the current HEAD to the specified state. This allows you to undo merges,
$ git config --global alias.g "grep --break --heading --line-number" pulls, commits, adds, and more. It's a great command but also dangerous if you don't
know what you are doing.
Examples: ```bash
// Search for "variableName" in all java files # Reset the staging area, to match the latest commit (leaves dir unchanged)
$ git grep 'variableName' -- '*.java' $ git reset
// Search for a line that contains "arrayListName" and, "add" or "remove" # Reset the staging area, to match the latest commit, and overwrite working dir
$ git grep -e 'arrayListName' --and \( -e add -e remove \) $ git reset --hard
Google is your friend for more examples # Moves the current branch tip to the specified commit (leaves dir unchanged)
[Git Grep Ninja](http://travisjeffery.com/b/2012/02/search-a-git-repo-like-a-ninja) # all changes still exist in the directory.
$ git reset 31f2bb1
/////////////////////////////////////// # Moves the current branch tip backward to the specified commit
// log # and makes the working dir match (deletes uncommited changes and all commits
/////////////////////////////////////// # after the specified commit).
$ git reset --hard 31f2bb1
```
Purpose: ### rm
Display commits to the repository.
Examples: The opposite of git add, git rm removes files from the current working tree.
// Show all commits
$ git log
// Show X number of commits ```bash
$ git log -n 10 # remove HelloWorld.c
$ git rm HelloWorld.c
// Show merge commits only
$ git log --merges
///////////////////////////////////////
// merge
///////////////////////////////////////
Purpose:
"Merge" in changes, from external commits, into the current branch.
Examples:
// Merge the specified branch into the current.
$ git merge branchName
// Always generate a merge commit when merging
$ git merge --no-ff branchName
///////////////////////////////////////
// mv
///////////////////////////////////////
Purpose:
Rename or move a file
Examples:
// Renaming a file
$ git mv HelloWorld.c HelloNewWorld.c
// Moving a file
$ git mv HelloWorld.c ./new/path/HelloWorld.c
// Force rename or move
// "existingFile" already exists in the directory, will be overwritten
$ git mv -f myFile existingFile
///////////////////////////////////////
// pull
///////////////////////////////////////
Purpose:
Pulls from a repository and merges it with another branch.
Examples:
// Update your local repo, by merging in new changes
// from the remote "origin" and "master" branch.
// git pull <remote> <branch>
$ git pull origin master
///////////////////////////////////////
// push
///////////////////////////////////////
Purpose:
Push, and merge changes from a branch to a remote & branch.
Examples:
// Push, and merge changes from a local repo to a
// remote named "origin" and "master" branch.
// git push <remote> <branch>
// git push => implicitly defaults to => git push origin master
$ git push origin master
///////////////////////////////////////
// rebase (caution)
///////////////////////////////////////
Purpose:
Take all changes that were committed on one branch, and replay them onto another branch.
*Do not rebase commits that you have pushed to a public repo*
Examples:
// Rebase experimentBranch onto master
// git rebase <basebranch> <topicbranch>
$ git rebase master oldTest
[Additional Reading.](http://git-scm.com/book/en/Git-Branching-Rebasing)
///////////////////////////////////////
// reset (caution)
///////////////////////////////////////
Purpose:
Reset the current HEAD to the specified state. This allows you to undo merges,
pulls, commits, adds, and more. It's a great command but also dangerous if you don't
know what you are doing.
Examples:
// Reset the staging area, to match the latest commit (leaves dir unchanged)
$ git reset
// Reset the staging area, to match the latest commit, and overwrite working dir
$ git reset --hard
// Moves the current branch tip to the specified commit (leaves dir unchanged)
// all changes still exist in the directory.
$ git reset 31f2bb1
// Moves the current branch tip backward to the specified commit
// and makes the working dir match (deletes uncommited changes and all commits
// after the specified commit).
$ git reset --hard 31f2bb1
///////////////////////////////////////
// rm
///////////////////////////////////////
Purpose:
The opposite of git add, git rm removes files from the current working tree.
Example:
// remove HelloWorld.c
$ git rm HelloWorld.c
// Remove a file from a nested dir
$ git rm /pather/to/the/file/HelloWorld.c
# Remove a file from a nested dir
$ git rm /pather/to/the/file/HelloWorld.c
``` ```
## Further Information ## Further Information
* [tryGit - A fun interactive way to learn Git.](http://try.github.io/levels/1/challenges/1) * [tryGit - A fun interactive way to learn Git.](http:#try.github.io/levels/1/challenges/1)
* [git-scm - Video Tutorials](http://git-scm.com/videos) * [git-scm - Video Tutorials](http:#git-scm.com/videos)
* [git-scm - Documentation](http://git-scm.com/docs) * [git-scm - Documentation](http:#git-scm.com/docs)
* [Atlassian Git - Tutorials & Workflows](https://www.atlassian.com/git/) * [Atlassian Git - Tutorials & Workflows](https:#www.atlassian.com/git/)
* [SalesForce Cheat Sheet](https://na1.salesforce.com/help/doc/en/salesforce_git_developer_cheatsheet.pdf) * [SalesForce Cheat Sheet](https:#na1.salesforce.com/help/doc/en/salesforce_git_developer_cheatsheet.pdf)

View File

@@ -343,7 +343,7 @@ class Bicycle {
speed -= decrement; speed -= decrement;
} }
public void setName(int newName) { public void setName(String newName) {
name = newName; name = newName;
} }

View File

@@ -12,7 +12,7 @@ Racket is a general purpose, multi-paradigm programming language in the Lisp/Sch
Feedback is appreciated! You can reach me at [@th3rac25](http://twitter.com/th3rac25) or th3rac25 [at] [google's email service] Feedback is appreciated! You can reach me at [@th3rac25](http://twitter.com/th3rac25) or th3rac25 [at] [google's email service]
```scheme ```racket
#lang racket ; defines the language we are using #lang racket ; defines the language we are using
;;; Comments ;;; Comments