Thursday 10 March 2016

Git Commands

Cited from Ry’s Git Tutorial

git --verison

to turn a directory into a Git repository

cd [dirname]; git init

A .git directory stores all the tracking data for our repository.

An untracked file is one that is not under version control.

You should only track source files and omit anything that can be generated from those files.

git add command tells Git to add the file to the repository.

A snapshot represents the state of your project at a given point in time.

Git’s term for creating a snapshot is called staging.

The git status command will only show us uncommitted changes. To view our project history, git log.

To tell Git who we are,
git config --global user.name "Your Name"
git config --global user.email your.email@example.com

The --global flag tells Git to use this configuration as a default for all of your repositories. Omitting it lets you specify different user information for individual repositories.

Another useful configuration is to pass a filename to git log filename to display file-specific history.

git checkout <commit-id>
View a previous commit.

Tags are convenient references to official releases and other significant milestones in a software project. It lets developers easily browse and check out important revisions. For example, we can now use the v1.0 tag to refer to the third commit instead of its random ID. To view a list of existing tags, execute git tag without any arguments.

git tag -a v1.0 -m "message"

Never make changes directly to a previous revision.

When using git revert, remember to specify the commit that you want to undo—not the stable commit that you want to return to. It helps to think of this command as saying “undo this commit” rather than “restore this version.”

In Git, a branch is an independent line of development.

The HEAD is Git’s internal way of indicating the snapshot that is currently checked out.

To create a new branch,
git branch branch-name

To checkout a branch,
git checkout branch-name

When the history of two branches diverges, a dedicated commit is required to combine the branches. This situation may also give rise to a merge conflict, which must be manually resolved before anything can be committed to the repository.

Conflicts occur when we try to merge branches that have edited the same content.

###################################################################
 







No comments:

Post a Comment