What is GIT?
Git is a free and open-source distributed version control system that can manage everything from tiny to extremely big projects with ease.
Git is simple to understand and use, with a small footprint and lightning-quick performance. With capabilities like inexpensive local branching, accessible staging areas, and numerous workflows, it outperforms SCM solutions like Subversion, CVS, Perforce, and ClearCase.
What are you going to learn from this article?
This lesson will show you how to add a new project to Git, edit it, and share the changes with other developers.
You might want to start with the first two chapters of The Git User's Manual if you're primarily interested in using Git to download a project, for example, to test the newest version.
You can get the documentation by using
$ git help log
Command.
How to config git username?
Before doing any action, it's a good idea to identify yourself to Git by providing your name and public email address. The simplest method is to:
$ git config --global user.name "Your Name Comes Here" $ git config --global user.email you@yourdomain.example.com
Import a new Project
Assume you're working on a tarball project. tar.gz file containing your initial work. As seen below, you may put it under Git revision control.
$ tar xzf project.tar.gz $ cd project $ git init
Git Will reply
Initialized empty Git repository in .git/
You've now established an empty Git repository in.git/, and you'll see a new directory named ".git" in the working directory.
Then, with git add:, instruct Git to take a snapshot of the contents of all files in the current directory (note the.).
$ git add .
git add is a command that allows you to add files to your repository.
This snapshot is now saved in Git's "index," which is a temporary staging area. With git commit, you may save the contents of the index in the repository indefinitely:
$ git commit
You'll be prompted for a commit message.
Making Changes
$ git add file1 file2 file3
You are now prepared to make a commitment. With the --cached option, you can view what's about to be committed with git diff:
$ git diff --cached
(Without —cached, git diff will display any changes you've made but haven't yet indexed.) You may also use git status to get a quick overview of the situation:
$ git status On branch master Changes to be committed: Your branch is up to date with 'origin/master'. (use "git restore --staged <file>..." to unstage) modified: file1 modified: file2 modified: file3
If you need to make any further changes, do so now and then update the index with the updated material. Finally, save your modifications by typing:
$ git commit
This will prompt you for another message describing the change, after which you will be prompted to record a new version of the project.
You may also use git add instead of executing git add first.
$ git commit -a
A word on commit messages: It's a good idea to start the commit message with a single brief (less than 50 characters) line describing the change, followed by a blank line, and then a more detailed description, even if it's not needed. The content in a commit message up to the first blank line is interpreted as the commit title, which is used throughout Git. For example, git-format-patch[1] converts a commit into an email, with the title appearing on the Subject line and the remainder of the commit appearing in the body.
$ git log
$ git log -p
$ git log --stat --summary
$ git branch experimental
$ git branch
experimental * master
$ git switch experimental
(edit file) $ git commit -a$ git switch master
(edit file) $ git commit -a
$ git merge experimental
$ git diff
$ git commit -a
$ gitk
$ git branch -d experimental
$ git branch -D crazy-idea
Comments
Post a Comment