当初咱们无论是公司或者是集体我的项目,都经常用到 Git, 作为一个开源的版本控制系统,在我用过的所有版本控制系统中,它是最好用的了(截止到写这篇文章的 2022 年)。这里记下一些常用命令。具体的命令大全能够参考 Git.
仓库 (Repository)
git init
, 创立一个新的本地仓库git clone
,check out a repository
提交代码
- status
git status
, 列出有改变,目前须要提交的文件。 - Add files
git add <filename>
git add *
, 增加一个或多个文件到 stating - Commit
git commit -m "Commit message"
, commit changes to head(but not yet to remote repository).
git commit -a
, commit any files you’ve added withgit add
, and also commit any files you’ve add since then. - Push
git push origin master
, send changes to the master branch of your remote repository.
撤销本地的改变
git checkout -- <filename>
, replace the changes in your working tree with the last content in the head. Changes already added to the index, as well as new files, will be keep.git fetch origin
git reset --hard origin/master
, 放弃本地所有的改变和提交,fetch the latest history from the server and point your local masrer branch at it.
分支 (branches)
git checkout -b <branchname>
, 创立一个新的分支,并且切换到它。git branch -d <branchname>
, 删除分支。git push origin <branchname>
,Push the branch to your remote repository, so others can use it.git push --all origin
, push all branches to your remote repository.git push origin :<branchname>
删除你近程仓库的分支。
update from remote repository
git pull
Fetch and merge changes on the remote server to your working diectory.2.git merge <brandbane>
, merge a different branch to your active branch.git diff
, view all the conflicts.
git digg --base <filename>
, view the conflicts against the base file.
git diff <sourcevbranch> <targetbranch>
, preview changes before mergegit add <filename>
, 解决抵触之后,手动增加更新过的文件