From 84ac5877f34de7fd57906f8c9a4e14fea4090dcb Mon Sep 17 00:00:00 2001 From: awalGarg Date: Wed, 4 Mar 2015 22:00:00 +0530 Subject: Added the handy -a switch --- git.html.markdown | 3 +++ 1 file changed, 3 insertions(+) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index 04350dd5..af65afb0 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -217,6 +217,9 @@ the changes made and a message created by the user. ```bash # commit with a message $ git commit -m "Added multiplyNumbers() function to HelloWorld.c" + +# automatically stage modified or deleted files, except new files, and then commit +$ git commit -a -m "Modified foo.php and removed bar.php" ``` ### diff -- cgit v1.2.3 From bdedf51a72156d925b1814776e272572a9c8e581 Mon Sep 17 00:00:00 2001 From: Avjinder Singh Sekhon Date: Mon, 1 Jun 2015 23:46:04 +0530 Subject: Added 'Stages of Git', link to Pro Git, and other forms of git help --- git.html.markdown | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index af65afb0..dd93dd88 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -79,6 +79,11 @@ this pointer will automatically update and point to the latest commit. 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. +###Stages of Git +* Committed - Files have been committed to the Git Database +* Modified - Changes have been made to a file but file has not been committed to Git Database yet +* Staged - Marks a modified file to go into your next commit snapshot + ### Conceptual Resources * [Git For Computer Scientists](http://eagain.net/articles/git-for-computer-scientists/) @@ -131,6 +136,10 @@ $ git help -a $ git help add $ git help commit $ git help init +# or git --help +$ git add --help +$ git commit --help +$ git init --help ``` ### status @@ -149,8 +158,8 @@ $ git help status ### add -To add files to the current working tree/directory/repo. If you do not `git add` new files to the -working tree/directory, they will not be included in commits! +To add files to the staging area/index. If you do not `git add` new files to the +staging area/index, they will not be included in commits! ```bash # add a file in your current working directory @@ -163,6 +172,8 @@ $ git add /path/to/file/HelloWorld.c $ git add ./*.java ``` +This only addds a file to the staging area/index, it doesn't commit it to the working directory/repo. + ### branch Manage your branches. You can view, edit, create, delete branches using this command. @@ -462,3 +473,5 @@ $ git rm /pather/to/the/file/HelloWorld.c * [GitGuys](http://www.gitguys.com/) * [Git - the simple guide](http://rogerdudler.github.io/git-guide/index.html) + +* [Pro Git](http://www.git-scm.com/book/en/v2) -- cgit v1.2.3 From 470da394f6641dd0a56f48da5bb5f451ea0cbcdc Mon Sep 17 00:00:00 2001 From: Avjinder Singh Sekhon Date: Mon, 1 Jun 2015 23:49:05 +0530 Subject: Fixed some typos --- git.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index dd93dd88..1b83e3a3 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -172,7 +172,7 @@ $ git add /path/to/file/HelloWorld.c $ git add ./*.java ``` -This only addds a file to the staging area/index, it doesn't commit it to the working directory/repo. +This only adds a file to the staging area/index, it doesn't commit it to the working directory/repo. ### branch -- cgit v1.2.3 From 628a4ccfc2d55de69a55622c9cd8a0d9d7819013 Mon Sep 17 00:00:00 2001 From: Avjinder Singh Sekhon Date: Wed, 3 Jun 2015 03:02:38 +0530 Subject: Changed the order of the Stages of Git --- git.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index 1b83e3a3..4bbc58e7 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -80,9 +80,9 @@ HEAD is a pointer that points to the current branch. A repository only has 1 *ac head is a pointer that points to any commit. A repository can have any number of heads. ###Stages of Git -* Committed - Files have been committed to the Git Database * Modified - Changes have been made to a file but file has not been committed to Git Database yet * Staged - Marks a modified file to go into your next commit snapshot +* Committed - Files have been committed to the Git Database ### Conceptual Resources -- cgit v1.2.3 From 92eef7f483fd4c1192aab8049e8b2f0e926523e4 Mon Sep 17 00:00:00 2001 From: Jake Prather Date: Sat, 19 Sep 2015 11:07:26 -0500 Subject: Add Udemy's new git tutorial as a resource. --- git.html.markdown | 2 ++ 1 file changed, 2 insertions(+) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index 4bbc58e7..bf8fce0c 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -462,6 +462,8 @@ $ git rm /pather/to/the/file/HelloWorld.c * [tryGit - A fun interactive way to learn Git.](http://try.github.io/levels/1/challenges/1) +* [Udemy Git Tutorial: A Comprehensive Guide](https://blog.udemy.com/git-tutorial-a-comprehensive-guide/) + * [git-scm - Video Tutorials](http://git-scm.com/videos) * [git-scm - Documentation](http://git-scm.com/docs) -- cgit v1.2.3 From 6611db502aafc9768254efb45495a9fb20a79c81 Mon Sep 17 00:00:00 2001 From: Ayush Date: Tue, 6 Oct 2015 00:44:05 +0530 Subject: Git: removed some clutter --- git.html.markdown | 68 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 31 deletions(-) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index bf8fce0c..3b83218c 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -8,17 +8,17 @@ contributors: filename: LearnGit.txt --- -Git is a distributed version control and source code management system. +Git is a distributed version control and source code management system. -It does this through a series of snapshots of your project, and it works -with those snapshots to provide you with functionality to version and +It does this through a series of snapshots of your project, and it works +with those snapshots to provide you with functionality to version and manage 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. +Version control is a system that records changes to a file(s), over time. ### Centralized Versioning VS Distributed Versioning @@ -42,8 +42,9 @@ Version control is a system that records changes to a file, or set of files, ove ### Repository -A set of files, directories, historical records, commits, and heads. Imagine it as a source code data structure, -with the attribute that each source code "element" gives you access to its revision history, among other things. +A set of files, directories, historical records, commits, and heads. Imagine it +as a source code data structure, 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. @@ -54,32 +55,33 @@ The .git directory contains all the configurations, logs, branches, HEAD, and mo ### Working Tree (component of repository) -This is basically the directories and files in your repository. It is often referred to -as your working directory. +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 a layer that separates your working tree -from the Git repository. This gives developers more power over what gets sent to the Git -repository. +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 repositories, or not! +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 repositories, 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. +A branch is essentially a pointer to the last commit you made. As you go on +committing, this pointer will automatically update to ooint 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. -###Stages of Git +### Stages of Git * Modified - Changes have been made to a file but file has not been committed to Git Database yet * Staged - Marks a modified file to go into your next commit snapshot * Committed - Files have been committed to the Git Database @@ -95,7 +97,7 @@ head is a pointer that points to any commit. A repository can have any number of ### init -Create an empty Git repository. The Git repository's settings, stored information, +Create an empty Git repository. The Git repository's settings, stored information, and more is stored in a directory (a folder) named ".git". ```bash @@ -144,8 +146,8 @@ $ git init --help ### status -To show differences between the index file (basically your working copy/repo) and the current -HEAD commit. +To show differences between the index file (basically your working copy/repo) +and the current HEAD commit. ```bash @@ -172,7 +174,8 @@ $ git add /path/to/file/HelloWorld.c $ git add ./*.java ``` -This only adds a file to the staging area/index, it doesn't commit it to the working directory/repo. +This only adds a file to the staging area/index, it doesn't commit it to the +working directory/repo. ### branch @@ -205,7 +208,8 @@ Updates all files in the working tree to match the version in the index, or spec $ git checkout # Checkout a specified branch $ git checkout branchName -# Create a new branch & switch to it, like: "git branch ; git checkout " +# Create a new branch & switch to it +# equivalent to "git branch ; git checkout " $ git checkout -b newBranch ``` @@ -268,7 +272,7 @@ $ git config --global alias.g "grep --break --heading --line-number" $ git grep 'variableName' -- '*.java' # Search for a line that contains "arrayListName" and, "add" or "remove" -$ git grep -e 'arrayListName' --and \( -e add -e remove \) +$ git grep -e 'arrayListName' --and \( -e add -e remove \) ``` Google is your friend; for more examples @@ -303,7 +307,7 @@ $ git merge --no-ff branchName ### mv -Rename or move a file +Rename or move a file ```bash # Renaming a file @@ -338,7 +342,7 @@ $ git pull origin master --rebase Push and merge changes from a branch to a remote & branch. ```bash -# Push and merge changes from a local repo to a +# Push and merge changes from a local repo to a # remote named "origin" and "master" branch. # git push # git push => implicitly defaults to => git push origin master @@ -347,23 +351,25 @@ $ git push origin master # To link up current local branch with a remote branch, add -u flag: $ git push -u origin master # Now, anytime you want to push from that same local branch, use shortcut: -$ git push +$ git push ``` ### stash -Stashing takes the dirty state of your working directory and saves it on a stack of unfinished changes that you can reapply at any time. +Stashing takes the dirty state of your working directory and saves it on a stack +of unfinished changes that you can reapply at any time. -Let's say you've been doing some work in your git repo, but you want to pull from the remote. -Since you have dirty (uncommited) changes to some files, you are not able to run `git pull`. -Instead, you can run `git stash` to save your changes onto a stack! +Let's say you've been doing some work in your git repo, but you want to pull +from the remote. Since you have dirty (uncommited) changes to some files, you +are not able to run `git pull`. Instead, you can run `git stash` to save your +changes onto a stack! ```bash $ git stash Saved working directory and index state \ "WIP on master: 049d078 added the index file" HEAD is now at 049d078 added the index file - (To restore them type "git stash apply") + (To restore them type "git stash apply") ``` Now you can pull! @@ -410,7 +416,7 @@ Now you're ready to get back to work on your stuff! [Additional Reading.](http://git-scm.com/book/en/v1/Git-Tools-Stashing) -### rebase (caution) +### rebase (caution) 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*. -- cgit v1.2.3 From 7b7ce666b66e897c115879d505104330923919ec Mon Sep 17 00:00:00 2001 From: Ayush Date: Tue, 6 Oct 2015 00:45:40 +0530 Subject: Git: added para for gitignore --- git.html.markdown | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index 3b83218c..c32d9c5d 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -144,6 +144,16 @@ $ git commit --help $ git init --help ``` +### ignore (set of) files + +To intentionally untrack file(s) & folder(s) from git. Typically meant for +private & temp files which would otherwise be shared in the repository. +```bash +$ echo "temp/" >> .gitignore +$ echo "private_key" >> .gitignore +``` + + ### status To show differences between the index file (basically your working copy/repo) -- cgit v1.2.3 From 037ff22ef63c5f37b6657e806695bb52f46a7ec3 Mon Sep 17 00:00:00 2001 From: Ayush Date: Tue, 6 Oct 2015 00:46:53 +0530 Subject: Git: added more clone options --- git.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index c32d9c5d..66b890c1 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -232,6 +232,10 @@ to a remote branch. ```bash # Clone learnxinyminutes-docs $ git clone https://github.com/adambard/learnxinyminutes-docs.git +# shallow clone - faster cloning that pulls only latest snapshot +$ git clone --depth 1 https://github.com/adambard/learnxinyminutes-docs.git +# clone only a specific branch +$ git clone -b master-cn https://github.com/adambard/learnxinyminutes-docs.git --single-branch ``` ### commit -- cgit v1.2.3 From e75a9e031bde60fae2c1972b5f6b18571acd4d99 Mon Sep 17 00:00:00 2001 From: Ayush Date: Tue, 6 Oct 2015 00:56:08 +0530 Subject: Git: added few random things --- git.html.markdown | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index 66b890c1..e20a4b88 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -106,15 +106,12 @@ $ git init ### config -To configure settings. Whether it be for the repository, the system itself, or global -configurations. +To configure settings. Whether it be for the repository, the system itself, +or global configurations ( global config file is `~/.gitconfig` ). ```bash # Print & Set Some Basic Config Variables (Global) -$ git config --global user.email -$ git config --global user.name - $ git config --global user.email "MyEmail@Zoho.com" $ git config --global user.name "My Name" ``` @@ -249,6 +246,9 @@ $ git commit -m "Added multiplyNumbers() function to HelloWorld.c" # automatically stage modified or deleted files, except new files, and then commit $ git commit -a -m "Modified foo.php and removed bar.php" + +# change last commit (this deletes previous commit with a fresh commit) +$ git commit --amend -m "Correct message" ``` ### diff @@ -300,8 +300,8 @@ Display commits to the repository. # Show all commits $ git log -# Show X number of commits -$ git log -n 10 +# Show only commit message & ref +$ git log --oneline # Show merge commits only $ git log --merges -- cgit v1.2.3 From 9e605ee35ced12a77f0c0c666c0019d40eaaeea6 Mon Sep 17 00:00:00 2001 From: Ayush Date: Tue, 6 Oct 2015 01:06:15 +0530 Subject: Git: fixed typo --- git.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index e20a4b88..b1347309 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -74,7 +74,7 @@ other repositories, or not! ### Branch A branch is essentially a pointer to the last commit you made. As you go on -committing, this pointer will automatically update to ooint the latest commit. +committing, this pointer will automatically update to point the latest commit. ### HEAD and head (component of .git dir) @@ -141,7 +141,7 @@ $ git commit --help $ git init --help ``` -### ignore (set of) files +### ignore files To intentionally untrack file(s) & folder(s) from git. Typically meant for private & temp files which would otherwise be shared in the repository. -- cgit v1.2.3 From 8f5f1240eb14919deed89c54f0b322bc11e1469c Mon Sep 17 00:00:00 2001 From: Heather Fenton Date: Thu, 8 Oct 2015 19:18:07 -0400 Subject: Git: Add Git Immersion tutorial as a resource --- git.html.markdown | 2 ++ 1 file changed, 2 insertions(+) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index b1347309..72079f6c 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -484,6 +484,8 @@ $ git rm /pather/to/the/file/HelloWorld.c * [Udemy Git Tutorial: A Comprehensive Guide](https://blog.udemy.com/git-tutorial-a-comprehensive-guide/) +* [Git Immersion - A Guided tour that walks through the fundamentals of git](http://gitimmersion.com/) + * [git-scm - Video Tutorials](http://git-scm.com/videos) * [git-scm - Documentation](http://git-scm.com/docs) -- cgit v1.2.3 From 93ced538e3e426b810bc2d4e621eae231c9515c4 Mon Sep 17 00:00:00 2001 From: Bruno Volcov Date: Tue, 13 Oct 2015 11:26:26 -0300 Subject: add documentation about git tags --- git.html.markdown | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index 72079f6c..971d53e4 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -5,6 +5,7 @@ contributors: - ["Jake Prather", "http://github.com/JakeHP"] - ["Leo Rudberg" , "http://github.com/LOZORD"] - ["Betsy Lorton" , "http://github.com/schbetsy"] + - ["Bruno Volcov", "http://github.com/volcov"] filename: LearnGit.txt --- @@ -76,6 +77,11 @@ other repositories, or not! A branch is essentially a pointer to the last commit you made. As you go on committing, this pointer will automatically update to point the latest commit. +### Tag + +A tag is a mark on specific point in history. Typically people use this +functionality to mark release points (v1.0, and so on) + ### HEAD and head (component of .git dir) HEAD is a pointer that points to the current branch. A repository only has 1 *active* HEAD. @@ -206,6 +212,28 @@ $ git branch -m myBranchName myNewBranchName $ git branch myBranchName --edit-description ``` +### tag + +Manage your tags + +```bash +# List tags +$ git tag +# Create a annotated tag +# The -m specifies a tagging message,which is stored with the tag. +# If you don’t specify a message for an annotated tag, +# Git launches your editor so you can type it in. +$ git tag -a v2.0 -m 'my version 2.0' +# Show info about tag +# That shows the tagger information, the date the commit was tagged, +# and the annotation message before showing the commit information. +$ git show v2.0 +# Push a single tag to remote +$ git push origin v2.0 +# Push a lot of tags to remote +$ git push origin --tags +``` + ### checkout Updates all files in the working tree to match the version in the index, or specified tree. -- cgit v1.2.3 From c613e3bc6a3c59214faaa6e6273cb98ab8a97c1d Mon Sep 17 00:00:00 2001 From: Romin Irani Date: Sun, 18 Oct 2015 06:19:24 +0530 Subject: Added Git and Github Tutorial Link --- git.html.markdown | 3 +++ 1 file changed, 3 insertions(+) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index 72079f6c..e9d62b69 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -499,3 +499,6 @@ $ git rm /pather/to/the/file/HelloWorld.c * [Git - the simple guide](http://rogerdudler.github.io/git-guide/index.html) * [Pro Git](http://www.git-scm.com/book/en/v2) + +* [An introduction to Git and GitHub for Beginners (Tutorial)](http://product.hubspot.com/blog/git-and-github-tutorial-for-beginners) + -- cgit v1.2.3 From 670e71c4990aefe739f108e15bf707eaf795f922 Mon Sep 17 00:00:00 2001 From: Chris54721 Date: Sun, 18 Oct 2015 13:47:03 +0200 Subject: [git/en] Fixed 'git pull' documentation While translating git.html.markdown to Italian, I found a mistake: `git pull` does not default to `git pull origin master`. By default, it updates the current branch by merging changes from its remote-tracking branch. --- git.html.markdown | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index f678f9d1..ed9aec15 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -371,9 +371,12 @@ Pulls from a repository and merges it with another branch. # Update your local repo, by merging in new changes # from the remote "origin" and "master" branch. # git pull -# git pull => implicitly defaults to => git pull origin master $ git pull origin master +# By default, git pull will update your current branch +# by merging in new changes from its remote-tracking branch +$ git pull + # Merge in changes from remote branch and rebase # branch commits onto your local repo, like: "git pull , git rebase " $ git pull origin master --rebase -- cgit v1.2.3 From 6d20f58cbd3022fb8990ace8f88f8f4c15591a88 Mon Sep 17 00:00:00 2001 From: Chris54721 Date: Sun, 18 Oct 2015 13:54:06 +0200 Subject: [git/en] Fixed 'git push' documentation The 'git push' documentation had the same problem of the 'git pull' one I just fixed. --- git.html.markdown | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index ed9aec15..bedc9853 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -390,9 +390,12 @@ Push and merge changes from a branch to a remote & branch. # Push and merge changes from a local repo to a # remote named "origin" and "master" branch. # git push -# git push => implicitly defaults to => git push origin master $ git push origin master +# By default, git push will push and merge changes from +# the current branch to its remote-tracking branch +$ git push + # To link up current local branch with a remote branch, add -u flag: $ git push -u origin master # Now, anytime you want to push from that same local branch, use shortcut: -- cgit v1.2.3 From 232ed30031541607e4a5d3e2a3892308092f3019 Mon Sep 17 00:00:00 2001 From: Marian Sievers Date: Thu, 22 Oct 2015 08:54:38 +0200 Subject: Add feature "fast branching" Add feature "fast branching". In contrast to SCM's like SVN, branching in Git is very fast. --- git.html.markdown | 1 + 1 file changed, 1 insertion(+) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index bedc9853..3e20c29f 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -34,6 +34,7 @@ Version control is a system that records changes to a file(s), over time. * Can work offline. * Collaborating with others is easy! * Branching is easy! +* Branching is fast! * Merging is easy! * Git is fast. * Git is flexible. -- cgit v1.2.3 From a4842767094537dfee57698edc3bcc2b74f1ecee Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 30 Oct 2015 19:58:33 +0000 Subject: Adds documentation for revert command Also mentions graph flag for the log command --- git.html.markdown | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index bedc9853..e7ca07d6 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -6,6 +6,7 @@ contributors: - ["Leo Rudberg" , "http://github.com/LOZORD"] - ["Betsy Lorton" , "http://github.com/schbetsy"] - ["Bruno Volcov", "http://github.com/volcov"] + - ["Andrew Taylor", "http://github.com/andrewjt71"] filename: LearnGit.txt --- @@ -333,6 +334,9 @@ $ git log --oneline # Show merge commits only $ git log --merges + +# Show all commits represented by an ASCII graph +$ git log --graph ``` ### merge @@ -499,6 +503,16 @@ $ git reset 31f2bb1 # after the specified commit). $ git reset --hard 31f2bb1 ``` +### revert + +Revert can be used to undo a commit. It should not be confused with reset which restores +the state of a project to a previous point. Revert will add a new commit which is the +inverse of the specified commit, thus reverting it. + +```bash +# Revert a specified commit +$ git revert +``` ### rm -- cgit v1.2.3 From f0a211b8dd082d9802067a24b8b39a62f867a7f1 Mon Sep 17 00:00:00 2001 From: Nathan Reynolds Date: Mon, 7 Mar 2016 11:33:19 +0000 Subject: Update link to Salesforce Git cheat sheet --- git.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index e7ca07d6..35f24b2d 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -540,7 +540,7 @@ $ git rm /pather/to/the/file/HelloWorld.c * [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](http://res.cloudinary.com/hy4kyit2a/image/upload/SF_git_cheatsheet.pdf) * [GitGuys](http://www.gitguys.com/) -- cgit v1.2.3 From 01bf2b1ec603e20592e6db60a8f5b568ecd18509 Mon Sep 17 00:00:00 2001 From: Divay Prakash Date: Fri, 18 Mar 2016 12:51:27 +0530 Subject: fixed whitespaces, content extending beyond 80 chars --- git.html.markdown | 97 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 41 deletions(-) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index 282abbd2..6472c462 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -24,9 +24,12 @@ Version control is a system that records changes to a file(s), 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. +* 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) @@ -42,7 +45,6 @@ Version control is a system that records changes to a file(s), over time. ## Git Architecture - ### Repository A set of files, directories, historical records, commits, and heads. Imagine it @@ -53,7 +55,8 @@ 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. +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) @@ -63,16 +66,16 @@ referred to as your working directory. ### Index (component of .git dir) -The Index is the staging area in git. It's basically a layer that separates your working tree -from the Git repository. This gives developers more power over what gets sent -to the Git repository. +The Index is the staging area in git. It's basically a 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 repositories, or not! +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 repositories, or not! ### Branch @@ -86,11 +89,14 @@ functionality to mark release points (v1.0, and so on) ### 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. +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. ### Stages of Git -* Modified - Changes have been made to a file but file has not been committed to Git Database yet +* Modified - Changes have been made to a file but file has not been committed +to Git Database yet * Staged - Marks a modified file to go into your next commit snapshot * Committed - Files have been committed to the Git Database @@ -99,14 +105,12 @@ head is a pointer that points to any commit. A repository can have any number of * [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 (a folder) named ".git". +Create an empty Git repository. The Git repository's settings, stored +information, and more is stored in a directory (a folder) named ".git". ```bash $ git init @@ -117,7 +121,6 @@ $ git init To configure settings. Whether it be for the repository, the system itself, or global configurations ( global config file is `~/.gitconfig` ). - ```bash # Print & Set Some Basic Config Variables (Global) $ git config --global user.email "MyEmail@Zoho.com" @@ -158,13 +161,11 @@ $ echo "temp/" >> .gitignore $ echo "private_key" >> .gitignore ``` - ### status To show differences between the index file (basically your working copy/repo) and the current HEAD commit. - ```bash # Will display the branch, untracked files, changes and other differences $ git status @@ -175,8 +176,8 @@ $ git help status ### add -To add files to the staging area/index. If you do not `git add` new files to the -staging area/index, they will not be included in commits! +To add files to the staging area/index. If you do not `git add` new files to +the staging area/index, they will not be included in commits! ```bash # add a file in your current working directory @@ -194,7 +195,8 @@ working directory/repo. ### branch -Manage your branches. You can view, edit, create, delete branches using this command. +Manage your branches. You can view, edit, create, delete branches using this +command. ```bash # list existing branches & remotes @@ -221,54 +223,64 @@ Manage your tags ```bash # List tags $ git tag + # Create a annotated tag # The -m specifies a tagging message,which is stored with the tag. # If you don’t specify a message for an annotated tag, # Git launches your editor so you can type it in. $ git tag -a v2.0 -m 'my version 2.0' + # Show info about tag # That shows the tagger information, the date the commit was tagged, # and the annotation message before showing the commit information. $ git show v2.0 + # Push a single tag to remote $ git push origin v2.0 + # Push a lot of tags to remote $ git push origin --tags ``` ### checkout -Updates all files in the working tree to match the version in the index, or specified tree. +Updates all files in the working tree to match the version in the index, or +specified tree. ```bash # Checkout a repo - defaults to master branch $ git checkout + # Checkout a specified branch $ git checkout branchName + # Create a new branch & switch to it # equivalent to "git branch ; git checkout " + $ git checkout -b newBranch ``` ### clone Clones, or copies, an existing repository into a new directory. It also adds -remote-tracking branches for each branch in the cloned repo, which allows you to push -to a remote branch. +remote-tracking branches for each branch in the cloned repo, which allows you +to push to a remote branch. ```bash # Clone learnxinyminutes-docs $ git clone https://github.com/adambard/learnxinyminutes-docs.git + # shallow clone - faster cloning that pulls only latest snapshot $ git clone --depth 1 https://github.com/adambard/learnxinyminutes-docs.git + # clone only a specific branch $ git clone -b master-cn https://github.com/adambard/learnxinyminutes-docs.git --single-branch ``` ### commit -Stores the current contents of the index in a new "commit." This commit contains -the changes made and a message created by the user. +Stores the current contents of the index in a new "commit." This commit +contains the changes made and a message created by the user. ```bash # commit with a message @@ -383,7 +395,8 @@ $ git pull origin master $ git pull # Merge in changes from remote branch and rebase -# branch commits onto your local repo, like: "git pull , git rebase " +# branch commits onto your local repo, like: "git pull , git +# rebase " $ git pull origin master --rebase ``` @@ -409,8 +422,8 @@ $ git push ### stash -Stashing takes the dirty state of your working directory and saves it on a stack -of unfinished changes that you can reapply at any time. +Stashing takes the dirty state of your working directory and saves it on a +stack of unfinished changes that you can reapply at any time. Let's say you've been doing some work in your git repo, but you want to pull from the remote. Since you have dirty (uncommited) changes to some files, you @@ -441,7 +454,8 @@ nothing to commit, working directory clean ``` You can see what "hunks" you've stashed so far using `git stash list`. -Since the "hunks" are stored in a Last-In-First-Out stack, our most recent change will be at top. +Since the "hunks" are stored in a Last-In-First-Out stack, our most recent +change will be at top. ```bash $ git stash list @@ -471,7 +485,8 @@ Now you're ready to get back to work on your stuff! ### rebase (caution) -Take all changes that were committed on one branch, and replay them onto another branch. +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*. ```bash @@ -485,8 +500,8 @@ $ git rebase master experimentBranch ### reset (caution) 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. +pulls, commits, adds, and more. It's a great command but also dangerous if you +don't know what you are doing. ```bash # Reset the staging area, to match the latest commit (leaves dir unchanged) @@ -504,11 +519,12 @@ $ git reset 31f2bb1 # after the specified commit). $ git reset --hard 31f2bb1 ``` + ### revert -Revert can be used to undo a commit. It should not be confused with reset which restores -the state of a project to a previous point. Revert will add a new commit which is the -inverse of the specified commit, thus reverting it. +Revert can be used to undo a commit. It should not be confused with reset which +restores the state of a project to a previous point. Revert will add a new +commit which is the inverse of the specified commit, thus reverting it. ```bash # Revert a specified commit @@ -550,4 +566,3 @@ $ git rm /pather/to/the/file/HelloWorld.c * [Pro Git](http://www.git-scm.com/book/en/v2) * [An introduction to Git and GitHub for Beginners (Tutorial)](http://product.hubspot.com/blog/git-and-github-tutorial-for-beginners) - -- cgit v1.2.3 From ddedb40ef88a8c7b0d26e0aaea0efb4b50ce521f Mon Sep 17 00:00:00 2001 From: Jason Stathopulos Date: Tue, 10 May 2016 10:30:32 -0400 Subject: Add Git Reflog Section To Git.html.markdown --- git.html.markdown | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index 6472c462..4d4b2a4e 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -7,6 +7,7 @@ contributors: - ["Betsy Lorton" , "http://github.com/schbetsy"] - ["Bruno Volcov", "http://github.com/volcov"] - ["Andrew Taylor", "http://github.com/andrewjt71"] + - ["Jason Stathopulos", "http://github.com/SpiritBreaker226"] filename: LearnGit.txt --- @@ -520,6 +521,31 @@ $ git reset 31f2bb1 $ git reset --hard 31f2bb1 ``` +### reflog (caution) + +Reflog will list most of the git commands you have done for a given time period, +default 90 days. + +This give you the a change to reverse any git commands that have gone wrong +for instance if a rebase is has broken your application. + +You can do this: + +1. `git reflog` to list all of the git commands for the rebase +``` +38b323f HEAD@{0}: rebase -i (finish): returning to refs/heads/feature/add_git_reflog +38b323f HEAD@{1}: rebase -i (pick): Clarify inc/dec operators +4fff859 HEAD@{2}: rebase -i (pick): Update java.html.markdown +34ed963 HEAD@{3}: rebase -i (pick): [yaml/en] Add more resources (#1666) +ed8ddf2 HEAD@{4}: rebase -i (pick): pythonstatcomp spanish translation (#1748) +2e6c386 HEAD@{5}: rebase -i (start): checkout 02fb96d +``` +2. Select where to reset to, in our case its `2e6c386`, or `HEAD@{5}` +3. 'git reset --hard HEAD@{5}' this will reset your repo to that head +4. You can start the rebase again or leave it alone. + +[Additional Reading.](https://git-scm.com/docs/git-reflog) + ### revert Revert can be used to undo a commit. It should not be confused with reset which -- cgit v1.2.3 From 1c3de94e762953cd863368745f7f1e8071feeb26 Mon Sep 17 00:00:00 2001 From: Danijar Hafner Date: Wed, 18 May 2016 18:05:13 +0200 Subject: Fix git pull --rebase explanation (#2262) --- git.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index 4d4b2a4e..47bac3ba 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -396,8 +396,8 @@ $ git pull origin master $ git pull # Merge in changes from remote branch and rebase -# branch commits onto your local repo, like: "git pull , git -# rebase " +# branch commits onto your local repo, like: "git fetch , git +# rebase /" $ git pull origin master --rebase ``` -- cgit v1.2.3 From 8888853e71eb7d6ae0bc8638a3d90b72907e34d9 Mon Sep 17 00:00:00 2001 From: Pavel Kulyov Date: Fri, 16 Sep 2016 14:25:41 +0400 Subject: Add very cool interactive tutorial (#2375) --- git.html.markdown | 2 ++ 1 file changed, 2 insertions(+) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index 47bac3ba..01dc92c1 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -573,6 +573,8 @@ $ git rm /pather/to/the/file/HelloWorld.c * [tryGit - A fun interactive way to learn Git.](http://try.github.io/levels/1/challenges/1) +* [Learn Git Branching - the most visual and interactive way to learn Git on the web](http://learngitbranching.js.org/) + * [Udemy Git Tutorial: A Comprehensive Guide](https://blog.udemy.com/git-tutorial-a-comprehensive-guide/) * [Git Immersion - A Guided tour that walks through the fundamentals of git](http://gitimmersion.com/) -- cgit v1.2.3 From 0e53a8a500b75a0b60a88b9830825fda3c06bbf8 Mon Sep 17 00:00:00 2001 From: Milo Gilad Date: Mon, 31 Jul 2017 10:26:51 -0400 Subject: Small changes to git docs * Added command to add all files in the working tree to the staging area * Fixed some markdown code formatting mistakes * Fixed some grammatical mistakes * Fixed some spelling mistakes --- git.html.markdown | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index 01dc92c1..e2376176 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -8,6 +8,7 @@ contributors: - ["Bruno Volcov", "http://github.com/volcov"] - ["Andrew Taylor", "http://github.com/andrewjt71"] - ["Jason Stathopulos", "http://github.com/SpiritBreaker226"] + - ["Milo Gilad", "http://github.com/Myl0g"] filename: LearnGit.txt --- @@ -23,7 +24,7 @@ manage your source code. Version control is a system that records changes to a file(s), over time. -### Centralized Versioning VS Distributed Versioning +### Centralized Versioning vs. Distributed Versioning * Centralized version control focuses on synchronizing, tracking, and backing up files. @@ -157,6 +158,7 @@ $ git init --help To intentionally untrack file(s) & folder(s) from git. Typically meant for private & temp files which would otherwise be shared in the repository. + ```bash $ echo "temp/" >> .gitignore $ echo "private_key" >> .gitignore @@ -189,6 +191,9 @@ $ git add /path/to/file/HelloWorld.c # Regular Expression support! $ git add ./*.java + +# You can also add everything in your working directory to the staging area. +$ git add -A ``` This only adds a file to the staging area/index, it doesn't commit it to the @@ -226,7 +231,7 @@ Manage your tags $ git tag # Create a annotated tag -# The -m specifies a tagging message,which is stored with the tag. +# The -m specifies a tagging message, which is stored with the tag. # If you don’t specify a message for an annotated tag, # Git launches your editor so you can type it in. $ git tag -a v2.0 -m 'my version 2.0' @@ -526,12 +531,12 @@ $ git reset --hard 31f2bb1 Reflog will list most of the git commands you have done for a given time period, default 90 days. -This give you the a change to reverse any git commands that have gone wrong -for instance if a rebase is has broken your application. +This give you the chance to reverse any git commands that have gone wrong (for instance, if a rebase has broken your application). You can do this: 1. `git reflog` to list all of the git commands for the rebase + ``` 38b323f HEAD@{0}: rebase -i (finish): returning to refs/heads/feature/add_git_reflog 38b323f HEAD@{1}: rebase -i (pick): Clarify inc/dec operators -- cgit v1.2.3 From 4d29f3f988e5612fa18c17066d9e00097b7b9149 Mon Sep 17 00:00:00 2001 From: Milo Gilad Date: Mon, 31 Jul 2017 10:30:24 -0400 Subject: Keeping lines under 80 chars --- git.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index e2376176..1cd2578e 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -531,7 +531,8 @@ $ git reset --hard 31f2bb1 Reflog will list most of the git commands you have done for a given time period, default 90 days. -This give you the chance to reverse any git commands that have gone wrong (for instance, if a rebase has broken your application). +This give you the chance to reverse any git commands that have gone wrong +(for instance, if a rebase has broken your application). You can do this: -- cgit v1.2.3 From 985d23a52b76593a120adff5381c2df3a80fe298 Mon Sep 17 00:00:00 2001 From: HairyFotr Date: Wed, 23 Aug 2017 10:14:39 +0200 Subject: Fix a bunch of typos --- git.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index 1cd2578e..088c109f 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -432,7 +432,7 @@ Stashing takes the dirty state of your working directory and saves it on a stack of unfinished changes that you can reapply at any time. Let's say you've been doing some work in your git repo, but you want to pull -from the remote. Since you have dirty (uncommited) changes to some files, you +from the remote. Since you have dirty (uncommitted) changes to some files, you are not able to run `git pull`. Instead, you can run `git stash` to save your changes onto a stack! @@ -521,7 +521,7 @@ $ git reset --hard $ 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 +# and makes the working dir match (deletes uncommitted changes and all commits # after the specified commit). $ git reset --hard 31f2bb1 ``` -- cgit v1.2.3 From 53604f0358c7ae771ce39254a7fe7588f2aceac5 Mon Sep 17 00:00:00 2001 From: Marko Cubela Date: Tue, 17 Oct 2017 09:38:17 +0200 Subject: added signed commit example --- git.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'git.html.markdown') diff --git a/git.html.markdown b/git.html.markdown index 088c109f..582f8863 100644 --- a/git.html.markdown +++ b/git.html.markdown @@ -292,6 +292,10 @@ contains the changes made and a message created by the user. # commit with a message $ git commit -m "Added multiplyNumbers() function to HelloWorld.c" +# signed commit with a message (user.signingkey must have been set +# with your GPG key e.g. git config --global user.signingkey 5173AAD5) +$ git commit -S -m "signed commit message" + # automatically stage modified or deleted files, except new files, and then commit $ git commit -a -m "Modified foo.php and removed bar.php" -- cgit v1.2.3