git use notes

Source: Internet
Author: User
Tags using git

1. Git init: Initialize a git repository.
Add:
Git init--bare < warehouse name > Create an empty database.
2. Add files to the Git repository in two steps:
The first step, use the command git add <filename>, note, can be used repeatedly, add multiple files;
Second, use the command git commit-m "commit instructions" to complete.
Add:
Git add: Adds all the changes in the current workspace to staging area.
Git commit-a: Add changes directly from the workspace to the repository. (This is equivalent to executing git add before executing git commit.) )
"Git commit-a" does not work on newly added files, delete files, etc., to display the Execute git add/git RM command
3. Git Status: Prints the status of the entire workspace.
4, Git diff <filename>: See what's changed.
Add:
git diff HEAD--filename: See the difference between the latest version in the workspace and the local repository, about filename

git diff "@{yesterday}": Compared to yesterday's repository.

git diff <commit-id> "@{2}": A specific version is compared to the second-to-last version.
5. Git log: View history commit commit record in system
such as: git log or git log--pretty=oneline
Where pretty specifies the format in which the content of the submitted record is printed, the optional values are: Oneline,short,medium,full,fuller,email,raw and some custom character formatting.
Add:
--graph can see the branching merge diagram.
--abbrev-commit Print short Commit-id.
6, git reset--hard <commit_id>: Sets the value of the head to the specified commit_id,
The head represents the current version ID,
head^ represents the previous version ID,
head^^ represents the previous version ID,
HEAD~100 represents the first 100 version IDs,
The version ID can also be viewed in the git log command, which is a commit.
Add:
Git reset: Revert to the previous version.
--mixed is the default option for Git reset, and his role is to reset the indexed content to the specified project version without changing everything in your work tree, just to indicate which files have not been updated.
The--soft option does not touch the location of the index, nor does it change anything in the work count. This option preserves all updates in your work tree and puts them in a pending state, which is equivalent to adding git add on a--mixed basis.
--hard restores the entire directory to a version, including all files.
7, git reflog: Record your every time about the history of the head of the command record
8. Workspace (working directory): is the current working directory.
Repository (Repository): Hidden directory under the workspace. Git.
Staging Area (stage): The index (or stage) file in the repository.
The git add command is to add file modifications to the staging area (stage);
The git commit command is to commit all the contents of staging area to the current branch. such as


9, Git checkout-<filename>: Undo the changes to the filename file in the workspace
Here are two things:
One is that after the modification has not been put into the staging area (ie: not yet using the git add command), now undo the change is back to the same state as the repository;
One is added to the staging area, and then modified, now undo the change is back to add to the state after the staging area.
Anyway, let's get this file back to the state of the last git commit or git Add.
Add:
git checkout <name>: Switch to the appropriate branch.
10, git reset HEAD <filename>: Undo the changes to filename in the staging area (this step is to undo the changes from staging area to the workspace, to undo the changes in the workspace, to further use of git checkout-< filename> command)
If the modifications have been submitted to the repository, you can use the git reset--hard <commit_id> command to rollback the version without pushing the local version to the remote.
(default option used:--mixed)
Add:
For git reset, see article 6th.
A description of the difference between "git checkout-<filename>" and 10th "git reset HEAD <filename>" in 9th:
Git checkout--<filename> is for the undo workspace modification, if staging area has the filename file at this time, it is revoked to the staging area filename, if there is no filename file in staging area, Revert to filename in the local repository, this command does not change the staging area and local repository. git reset HEAD-the <filename> command is for undo staging area, which restores the contents of staging area to the workspace, which is equivalent to git add <filename> 's inverse operation.
11, git rm <filename>: In the staging area record to delete the file filename, use the git commit command to submit the deletion request, delete the file from the repository.
12, ssh-keygen-t rsa-c "[Email protected]": use their own mail inUser Home DirectoryUnder Generate SSH key. (To run this command in the home directory)
-t Specifies the encryption method, the value can be: RSA, DSA, the default is: DSA
-C is to add the annotation comment, can not own the mail, also can not this item.
13. Git remote add origin [email protected]:<github username >/< Warehouse name >.git associates the local repository with the warehouse on GitHub.
Origin is the name of the remote library.
The premise of this command is that both the local repository and the remote repository have been established, and the role of the command is to correlate the two and not create anything new!
14. Git push-u Origin master: pushes all the contents of the local library to the remote library. (Add-u only when the first push is taken)
15, git config--global user.name "username": Configure the Default user name.
16, git config--global user.email "": Configure the default email, it is best to use the same email when registering.
Add: Config file in ~/.gitconfig
17, git clone [email protected]:< username >/< warehouse name >.git: Clone repository from remote library to local.
Add:
git clone. /some/new/directory: Clones the repository under the current directory to a new directory.
git clone [email protected]:< user name >/< warehouse name >.git/some_other_path/< warehouse name >-o O
"/some_other_path/< Warehouse name >" Can not be written by default placed in the Repository name folder in the current directory,
"-O" renames the remote repository alias, which is the default origin
18, Git branch: View branch.
Add:
Git branch--set-upstream branch-name origin/branch-name: Create a link relationship between the native branch and the remote branch.
Git branch--set-upstream-to=o/server_side_branch_name your_branch_name
19, Git branch <name>: Create branch name.
20, Git checkout <name>: Switch to Branch name.
Add:
git checkout <commit-id>: This action takes you back to the past while saving the newer commits. (a bit like entering a past time point, cutting this point of time as a new branch; it's a new unnamed branch, named and saved using Git checkout-b).

git checkout "@{10 minutes Age}": Switch to version 10 minutes ago (Commit-id)

Git checkout "@{5}": Switch to the 5th to the bottom of the Commit-id.

21, Git checkout-b <name>: Create and switch to branch name.
Add:
Equivalent to the effect of Git branch <name> and git checkout <name> two commands.
Git checkout-b <name> origin/<name> Create remote origin's name branch to local.
22, git merge <name>: Merges the name branch into the current branch.
If there is a conflict at the time of merging, Git will tell us which file has a conflict (git status will also tell us the conflicting file) and must manually resolve the conflict after the commit.
Add:
Git merge--no-ff-m "description information" Branchname
The--NO-FF parameter indicates that the merge with Fast forward mode is prohibited and should create a new commit for this merge, so join-M to write the commit description.
23, Git branch-d <name>: Delete branch name.
Add:
Git branch-d <name>: forcibly delete that branch. This command is used when a branch is not merged, but you want to delete it.
git branch-m [<oldbranch>] <newbranch>: Move or rename a branch.
24, git stash: The current work site storage to the work stack (into the stack operation).
Add:
Changes that are not added to the local repository in the staging area and workspace are not part of a branch, and when you switch a branch, use git status to see that the unsaved changes are still there, so the git stash command appears to keep those changes that you don't want to commit.
Now that you create a new test file in the BR1 branch and add it to staging area using the git add Test command, you switch to the BR2 branch, and the results viewed with GIT status are the same as the results of using GIT status in the BR1 branch. In the BR2 branch, using the git commit-m "XXX" command to submit the contents of the staging area to the repository, the test file belongs to Br2, and you cannot find any information about the test file after switching to BR1.
25. Git Stash list: View the contents of the stack in the storage work site.

26. Git stash apply [email protected]{n}: Return the nth work site in the work stack.

27, Git stash drop: Delete the first job site in the work stack.
28, git stash pop: reply to the work site while the corresponding content from the work stack deleted. (Out-of-stack operation).
29. Git Remote: View remote Library information.
-V: View the remote library details, where fetch is the fetch address, and push is the push address.
30. Git Pull: Fetch the latest submissions from others from the remote.
Download the database from the server and merge it with your own database.
git fetch: Download the database from the server and put it into a new branch, not merging with your own database.
Add:
Git pull/the/other/clone: Crawling updates from another clone.
Git pull is quite similar to git fetch and git merge orign/<branch>
31, git tag <name> [Commit-id]: Create a label at Commit-id, Commit-id default to head.
-A tagname-m "Blablabla ...": Specify label information.
-S Tagname-m "Blablabla ..." : You can use the PGP signature tag.
32. Git tag: View all tags.
33, git show <tagname>: View tag details.
34, Git tag-d <tagname>: delete local tags.
35, git push origin:refs/tags/tagname: delete a remote tag.
36, Git push origin origin tagname: Push tag to remote.
37, Git push origin--tags: Push all tags to remote.
38.. gitignore file: Ignore special files, Https://github.com/github/gitignore.
39. Git whatchanged:
40, git mv: rename files or folders. (Git mv oldfile newfile)
41, git revert <commit-id>: will restore the commit of a specific hash value. (That is, cancel the submission of this step)
42, Git Cherry-pick <commit-id>:??
43, Git rebase-i head~10: Re-modify the submission journal.
44, Git blame <file>: Lists the file's modification history.

Main reference: Liaoche blog

git use notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.