Git learning Diary < a >

Source: Internet
Author: User

Git Starts from scratch

thePost-installation configuration
git config--global user.name "Your name"
git config--global user.email "Your Email"

No.2Create a repository initialization
Go to target directory
GIT init//Initialize a repository

Add a file in two steps:
git add <filename>//Add Files
Git commit//Commit

No.3Current state of the warehouse
git status

View the contents of a file modification
git diff <filename>
Workingtree working directory: Git can know all the changes in the working directory
The index Add command submits the Workingtree to index
Commit is finally submitted to the warehouse
git diff <filename> see the difference between working directory and index
git diff--cached <filename> See the difference between index and commit
git diff HEAD <filename> See the difference between Worktree and commit

No.4Review the history of submissions to determine which version to fall back to
git log
git log--pretty=oneline//Line display

Fallback version
git reset--hard head^//Last version
git reset--hard head^^//On the first version and so on
git reset--hard head~100//up to 100 versions

Git reset--hard < version number >//fallback to version number

git reflog View the command history to determine which version of the ' Future '

No.5Undo Changes
① when not add to staging area
Git checkout--<filename> undo workspace modifications Recover from repository
② when already add to staging area
git reset HEAD <filename> Restore from staging area to workspace
Then checkout
③ when a commit is made to a repository
Fallback version
No.6deleting files
git rm removed from working directory
Git commit to Repository

Undo Delete
When there is no commit:
Fallback version git reset HEAD--helloworld.py
Git checkout--helloworld.py

Already commits:
Entire repository fallback git reset-hard head^
No.7Remote Warehouse
Create SSH key
Ssh-keygen-t rsa-c "[Email protected]"

The. SSH directory found in the user's home directory with Id_rsa and id_rsa.pub two files
Log on to GitHub, open the "Account Settings", "SSH Keys" page,
Then, click "Add SSH Key" and fill in any title,
Paste the contents of the Id_rsa.pub file in the key text box

To associate a remote library, use the command:
git remote add origin [email protected]:p ath/repo-name.git;
When associated, use the command
Git push-u Origin Master
For the first time, all content of the master branch is pushed;
Thereafter, after each local commit, you can use the command whenever necessary
Git push Origin Master
Push the latest changes;

Cloning from a remote library
git clone [email protected]:<username>/<repo-name>.git

No.8Branch Management

GIT encourages the use of branching:

View branches: Git branch

Create a branch: Git branch <name>

Switch branches: git checkout <name>

Create + switch branches: git checkout-b <name>

Merge a branch to the current branch: git merge <name>

Delete branch: Git branch-d <name>









Git learning Diary < a >

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.