【note】common Git commands(git常用命令)

Git is a tool to save versions of your code.

git init # initialize, set up all the tools Git needs to begin tracking changes made to the project
git status # check the status of those changes
git add <filename> # add a file to the staging area
git add <filename1> <filename2> <filename3> … # commit them to a repository in a single commit
git diff <filename> # check the differences between the working directory and the staging area
# press q on the keyboard to restore the terminal
git commit -m “abcdefg” # A commit permanently stores changes from the staging area inside the repository
git log # Commits are stored chronologically in the repository and can be viewed with ‘git log’
# SHA: A 40-character code, uniquely identifies the commit
git remote add origin https://github.com/liuchuo/123456.git # remote repository url
git push -u origin master # set upstream for git pull on master branch
git push # push the commit to remote repository
git show HEAD # the most recently made commit is the HEAD commit.
# the output of this command will display everything the git log command displays for the HEAD commit, plus all the file changes that were commited.
git checkout HEAD <filename> # restore the file in your working directory to look exactly as it did when you last made a commit
git checkout — <filename> # discard the change in working directory
git reset HEAD <filename> # it does not discard file changes from the working directory, it just removes them from the staging area
git reset <commit_SHA> # rewind to the part before you made the wrong turn
# commit_SHA works by using the first 7 characters of the SHA of a previous commit
# head goes to a previously made commit of your choice, but not discard file changes form the working directory
git branch # check what branch you are currently on (* is showing you what branch you’re on)
git branch <new_branch_name> # create a new branch
# new branch name can’t contain whitesapces
git checkout <branch_name> # switch to the new branch
git merge <branch_name> # merge branch_name to master, firstly switch over to the master branch
# if merge conflict, fix conflicts -> add -> commit, then git merge
git branch -d <branch_name> # delete branch
git clone <remote_location> <clone_name> # get your own replica of the remote repository
# remote_location tells Git where to go to find the remote. This could be a web address, or a filepath
git remote -v # see a list of a Git project’s remotes
git fetch # see if changes have been made to the remote, this command will not merge changes from the remote into your local repository
git merge origin/master # integrate origin/master into your local master branch
git push origin <branch_name> # push a local branch to the origin remote


❤ 点击这里 -> 订阅《PAT | 蓝桥 | LeetCode学习路径 & 刷题经验》by 柳婼

❤ 点击这里 -> 订阅《从放弃C语言到使用C++刷算法的简明教程》by 柳婼

❤ 点击这里 -> 订阅PAT甲级乙级、蓝桥杯、GPLT天梯赛、LeetCode题解离线版