1. Edit
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. As you work, you selectively stage these modified files and then commit all those staged changes, and the cycle repeats.
tracked vs untracked
Each file in working directory can be in one of two states:
Tracked files are files that were in the last snapshot; they can be:
|
2. Staging
stage some of your files and commit them without committing all of the other modified files in working directory.
This allows you to stage only portions of a modified file.
Git has something called the "staging area" or "index". This is an intermediate area where commits can be formatted and reviewed before completing the commit. |
3. Tagging
Tag specific points in a repository’s history as being important.
Typically, people use this functionality to mark release points (v1.0, v2.0 and so on)
3.1. Listing Your Tags
git tag
Listing tag wildcards requires -l or --list option If you want just the entire list of tags, running the command git tag implicitly assumes you want a listing and provides one; the use of -l or --list in this case is optional. If, however, you’re supplying a wildcard pattern to match tag names, the use of -l or --list is mandatory. |
3.2. Creating Tags
Git supports two types of tags:
-
lightweight
-
annotated
git tag -a v1.4 -m "my version 1.4"
The -m specifies a tagging message, which is stored with the tag
git tag v1.4-lw
To create a lightweight tag, don’t supply any of the -a, -s, or -m options, just provide a tag name
A lightweight tag is very much like a branch that doesn’t change — it’s just a pointer to a specific commit. Annotated tags, however, are stored as full objects in the Git database. They’re checksummed; contain the tagger name, email, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG).
|
3.3. Sharing Tags
By default, the git push command doesn’t transfer tags to remote servers.
You will have to explicitly push tags to a shared server after you have created them.
This process is just like sharing remote branches
git push origin v1
git push pushes both types of tags
git push <remote> --tags will push both
|
3.4. Deleting Tags
To delete a tag on your local repository, you can use git tag -d <tagname>
Remove our lightweight tag above as follows:
git tag -d v1.4-lw
Note that this does not remove the tag from any remote servers. |
3.4.1. remove from server
git push origin --delete <tagname>
3.5. Checking out Tags
If you want to view the versions of files a tag is pointing to, you can do a git checkout of that tag, although this puts your repository in “detached HEAD” state, which has some ill side effects:
git checkout v2.0.0
In “detached HEAD” state
|
One of the more helpful options is -p or --patch, which shows the difference (the patch output) introduced in each commit.
"Pro Git book" by Scott Chacon and Ben Straub , used under CC BY-NC-SA 3.0 / Desaturated from original