###### tags: `git` # git --- > [ToC] --- ## [教材](https://hackmd.io/@zxjte9411/BJ7X_PtgF#/) ==以下操作請於 Powershell 或 Git Bash 下執行== ## global config ``` git config --global user.email "you@example.com" git config --global user.name "your name" git config --global core.editor "code --wait" 或 vim git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" ``` ## 建立名為 folderName 的資料夾,列出檔案並進行git init ``` mkdir {folderName} ls git init ``` ## 新增一個 README.md 並commit ``` git status echo "Hello git!" > README.md git status cat README.md git add README.md 或 git add . git status git commit -m "commit 的訊息" git status git log 或 git lg 或 git log --graph --oneline ``` ## 新增文字至 README.md 並還原成前一個版本 ``` echo "Hello world!" >> README.md git diff git status git commit -a -m "commit的訊息" git lg git checkout {hash 雜湊值} cat README.md git lg ``` ## git branch 分支的應用 ``` git branch git checkout master git branch hello git branch git lg git checkout {hash 雜湊值} -b {branch 名稱} git checkout hello git lg git checkout master git branch -D hello ``` master 上的 `README.md` => `A` ``` Hello git! Hello world! hello ``` branch1 上的 `README.md` => `B` ``` Hello git! Hello world! world ``` ## git merge 合併的應用 ``` git lg git checkout branch1 git checkout master git lg echo "hello" >> README.md git add . git commit -m "hello" git lg git checkout branch1 git branch hello echo "world" >> README.md git commit -a -m "world" git lg git checkout master git lg git merge branch1 git status vim README.md (修改成你想要的樣子,並存檔) git add . git commit -m "merge" git lg ``` 衝突行為第三行 hello 跟 world 實作方式 建立一個新 commit 改為 `A` checkout 回 branch1 建立另外一個新 commit 改為 `B` checkout 回 master git merge `B` 的雜湊 ### vim 小提示 ``` i 進入insert mode esc 退出insert mode :wq 儲存並退出 ``` ## git clone ``` cd .. git clone https://github.com/109598023/Object-Oriented_Programming git remote -v git remote remove origin git remote -v git remote add origin {自己的專案 repository} git remote -v git push -u origin master --force ``` ## 之前下過的指令(限本機) ``` git reflog ``` ## 復原最新的版本 ``` git reset --hard master //尚未 commit git reset --hard {hash 雜湊值} ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up