Git Basics【Git Basics Supplement】
Getting a Git Repository [Create Git Repository]
Generally, there are two typical ways to create a Git repository:
- Initialize a directory as a new warehouse;
- Clone a remote warehouse;
Short Status【Simple Status】
If you run git status -s
or git status --short
you get a far more simplified output from the command: The
left letter represents the status of the temporary storage area, and the right letter represents the work area status.
The description of each letter in the picture is as follows:
- A- represents the newly added file that has been put into the temporary storage area;
- M-represents the file that has been modified, the green M on the left represents the modification has been temporarily saved, and the red M on the right represents the modified that has not been temporarily saved;
- ?-Represents new files that are not tracked
Use the git status
view as follows:
further explanation:
- readme is
git add
the new file after execution ; - test1 is
git add
the file that was executed after modification and then modified; - test2 is the unexecuted
git add
file after modification ; - readme2 is a newly created file that is not tracked.
Ignoring Files [Ignoring Files]
In the root directory of the project, add .gitignore
files and write file formats that need to be ignored by Git according to the rules. For example, write the following:
*.[oa]
*~
#忽略自身??
.gitignore
Undoing Things【Undoing】
1) git commit --amend
Instructions
Sometimes we found that a few files were missing and not added after the submission, or the submission information was written incorrectly. At this point, you can run the commit command with the --amend option to try to resubmit.
git commit --amend
Before executing this command, we can git add
wait for the operation and then resubmit, which is equivalent to adding some content on the basis of the previous submission. Note that this operation cannot be restored, and there is no history. This submission will overwrite the previous submission.
2) Unstaging a Staged File [Unstaging a Staged File]
git reset HEAD <file>...
It’s true that git reset can be a dangerous command, especially if you provide the
–hard flag.
3) Unmodifying a Modified File [Unmodifying a Modified File]
git checkout -- <file>...
This revocation is based on the staging area.
Working with Remotes【Remote operation】
1) Remote warehouse management
git remote [-v]
git remote add <shortname> <url>
git remote rename old new
git remote rm <shortname>
2) Fetching and Pulling from Your Remotes [Pull code]
git fetch <remote>
git pull <remote>
3) Pushing to Your Remotes【Push Code】
git push <remote> <branch>
4) Inspecting a Remote【View a remote warehouse】
git remote show <remote>
Tagging【Tag Operation】
1) Listing Your Tags [Search Tags]
git tag
git tag -l "v1.8.5*"
2) Creating Tags[Create Tags]
Git supports two types of tags: lightweight and annotated.
Lightweight tags and annotation tags
#1.Annotated Tags
git tag -a v1.0 -m "my version v1.0"
#2.Lightweight Tags
git tag v1.0-lw
#3.查看标签信息
git show v1.0
3) Tagging Later [Add Tag]
git tag -a v1.2 9fceb02
4) Sharing Tags [Sharing Tags]
git push <remote> <tagname>
git push <remote> --tags
5) Deleting Tags [deleting tags]
git tag -d <tagname>
There are two ways to synchronize to the remote warehouse:
git push <remote> :refs/tags/<tagname>
git push <remote> --delete <tagname>
6) Checking out Tags [check out tags]
git checkout <tagname>
git checkout -b <branchname> <tagname>
Git Aliases [Git Aliases]
1)可能会需要的别名
If you don’t want to type
the entire text of each of the Git commands, you can easily set up an alias for each command using
git config. Here are a couple of examples you may want to set up:
$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
$ git config --global alias.st status
2) Cancel temporary storage
$ git config --global alias.unstage 'reset HEAD --'
At this point, the following two commands are equivalent
$ git unstage fileA
$ git reset HEAD -- fileA
3) View the last submission information
$ git config --global alias.last 'log -1 HEAD'
如此只需要输入
$git last