Today, I almost lost all the code I wrote for two weeks. The specific reason is that the code I wrote during the development of new functions has not been committed. As a result, the leader told me to put the newly developed functions into a new branch, but I only used Git add. Git commit -m: git add. Git commit -m: git add. Git commit -m: git add. Also can check the history record, through the method of rolling back, the code came back really scared me out of a cold sweat, through this matter I still do a consolidation of git knowledge, but also to deepen their impression of Git.

Basic knowledge of

Register your account first

Git config --global user.name "name" git config --global user.emailCopy the code

Create a local Git repository

git init
Copy the code

View the status of related files

git status
Copy the code

Add to staging area

Git add. // Add all filesCopy the code

Files are submitted to the warehouse

Git commit -mCopy the code

See what has changed in a file

Git diff file nameCopy the code

Check the history

git log
Copy the code

Version back

Git reset --hard HEAD^ // Go back to the previous versionCopy the code

View the rollback version

git reflog
Copy the code

Restore the rollback version

Git reset --hard version number git reset --hard version numberCopy the code

View the contents of a file

The cat filenameCopy the code

If you don’t want to git add and don’t know what’s changed in the current file, go back to the last file state and abbreviate (discard workspace changes).

Git checkout -- file nameCopy the code

Create the dev branch

Git checkout dev //Copy the code

See the branch

git branch
Copy the code

Merging branches

Git merges other branchesCopy the code

Delete the branch

Git branch -d cannot use the current branch nameCopy the code