Introduction of git

Git is an open source distributed version control system designed to handle any project, small or large, with agility and efficiency.

Git is different from SVN

  • GIT is distributed version control, SVN is centralized version control.
  • GIT stores content as metadata, while SVN stores content as files.
  • GIT does not have a global version number, whereas SVN does.
  • GIT’s content integrity is superior to SVN’s: GIT’s content storage uses the SHA-1 hash algorithm.
  • GIT branches are different from SVN branches: branches are nothing special on SVN, just another directory in the repository.
  • GIT does most of the work offline.

Git installed

For Windows, download and install the software from https://git-scm.com/

Configure git

Open Git bash after successful installation

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
Copy the code

Git git

  • Initialize the Git repository in the project root directory
$ git init
Copy the code
  • Add files
$ git add <file>
Copy the code
  • submit
$ git commit -m <message>
Copy the code
  • View the current workspace status
$ git status
Copy the code
  • View the file modification
$ git diff <file>
Copy the code
  • View the commit history
$ git log

$ git log --pretty=oneline
Copy the code
  • Version back
$git reset --hard HEAD^ $git reset --hard < version ID>Copy the code
  • View operation history
$ git reflog
Copy the code
  • Undo modified file
$git checkout -- <file>Copy the code
  • Delete the file
$ git rm <file>
Copy the code
  • Associated remote warehouse
$ git remote add origin <address>
Copy the code
  • Commit to the remote repository
$git push -u origin master $git push origin masterCopy the code
  • Clone the warehouse locally
$ git clone <address>
Copy the code

– View branches

$ git branch
Copy the code
  • Create a branch
$git branchCopy the code
  • Switch branch
$git checkout < branch name >Copy the code
  • Create + switch branch shorthand
$git checkout -b < branch name >Copy the code
  • Merging branches
$git merge --no-ff -m $git merge --no-ff -m $git merge --no-ff -m"merge with no-ff"< branch name >Copy the code
  • Delete the branch
$ git branch -d$git branch -d < branch name >Copy the code
  • Retrieves updates from the remote branch and merges them with the specified local branch
$ git pull
Copy the code
  • Establish local branch and remote branch associations
Git branch --set-upstream < upstream > originCopy the code