現(xiàn)在我們無論是公司或者是個人項目额湘,都常常用到Git,作為一個開源的版本控制系統(tǒng)蚁堤,在我用過的所有版本控制系統(tǒng)中,它是最好用的了(截止到寫這篇文章的2022年)。這里記下一些常用命令勺爱。具體的命令大全可以參考Git.
倉庫(Repository)
-
git init
, 創(chuàng)建一個新的本地倉庫 -
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>
, 創(chuàng)建一個新的分支琐鲁,并且切換到它。 -
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 merge -
git add <filename>
,解決沖突之后,手動添加更新過的文件