Config file location --global use global config file --system use system config file --local use repository config file --worktree use per-worktree config file -f, --file <file> use given config file --blob <blob-id> read config from given blob object
#修改并提交到暂存区 (base) PS C:\Users\95734\Desktop\gittest> git add .\text1.txt (base) PS C:\Users\95734\Desktop\gittest> git status On branch master
No commits yet
Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: text1.txt
(base) PS C:\Users\95734\Desktop\gittest> git commit -m"wrote a new file" #提交到版本库 (base) PS C:\Users\95734\Desktop\gittest> git commit -m"wrote a new file" [master (root-commit) b8a15e1] wrote a new file 1 file changed, 2 insertions(+) create mode 100644 text1.txt (base) PS C:\Users\95734\Desktop\gittest> git status On branch master nothing to commit, working tree clean
版本回退 当我们发现自己的修改发生了错误,需要修改,这个时候就需要引出一种版本回退机制,来帮助我们控制版本修改。不得不先提到一个东西head。 这要从git的分支说起,git 中的分支,其实本质上仅仅是个指向 commit 对象的可变指针。git 是如何知道你当前在哪个分支上工作的呢?其实答案也很简单,它保存着一个名为 HEAD 的特别指针。在 git 中,它是一个指向你正在工作中的本地分支的指针,可以将 HEAD 想象为当前分支的别名。
(base) PS C:\Users\95734\Desktop\gittest> git add .\text2.txt (base) PS C:\Users\95734\Desktop\gittest> git commit -m"add another file" [masterf9ccede] add another file 1 file changed, 1 insertion(+) create mode 100644 text2.txt (base) PS C:\Users\95734\Desktop\gittest> git log --pretty=oneline f9ccedee1ad66749b11331650bcf61cdceab3e95 (HEAD -> master) add another file b8a15e1e0b045c4dbf23e66b382868178e8bfbe5 wrote a new file (base) PS C:\Users\95734\Desktop\gittest> git reset --hard b8a15 HEAD is now at b8a15e1 wrote a new file (base) PS C:\Users\95734\Desktop\gittest> git log --pretty=oneline b8a15e1e0b045c4dbf23e66b382868178e8bfbe5 (HEAD -> master) wrote a new file (base) PS C:\Users\95734\Desktop\gittest> git reflog b8a15e1 (HEAD -> master) HEAD@{0}: reset: moving to b8a15 f9ccede HEAD@{1}: commit: add another file b8a15e1 (HEAD -> master) HEAD@{2}: commit (initial): wrote a new file (base) PS C:\Users\95734\Desktop\gittest> git reset --hard f9cced HEAD is now at f9ccede add another file
(base) PS C:\Users\95734\Desktop\gittest> git checkout -b dev Switched to a new branch 'dev' (base) PS C:\Users\95734\Desktop\gittest> git branch * dev main (base) PS C:\Users\95734\Desktop\gittest> git add .\text4.txt (base) PS C:\Users\95734\Desktop\gittest> git commit -m"dev test" [deve65406f] dev test 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 text4.txt (base) PS C:\Users\95734\Desktop\gittest> git checkout main Switched to branch 'main' Your branch is up to date with 'origin/main'. (base) PS C:\Users\95734\Desktop\gittest> dir
(base) PS C:\Users\95734\Desktop\gittest> git add .\text1.txt (base) PS C:\Users\95734\Desktop\gittest> git commit -m"change the text1 on main" [main7ad011f] change the text1 on main 1 file changed, 2 insertions(+), 1 deletion(-) (base) PS C:\Users\95734\Desktop\gittest> git checkout dev Switched to branch 'dev' (base) PS C:\Users\95734\Desktop\gittest> git add .\text1.txt (base) PS C:\Users\95734\Desktop\gittest> git commit -m"change the text2 on dev" [dev880c3c6] change the text2 on dev 1 file changed, 2 insertions(+), 1 deletion(-) (base) PS C:\Users\95734\Desktop\gittest> git checkout main Switched to branch 'main' Your branch is ahead of 'origin/main' by 3 commits. (use "git push" to publish your local commits) (base) PS C:\Users\95734\Desktop\gittest> git merge dev Auto-merging text1.txt CONFLICT (content): Merge conflict in text1.txt Automatic merge failed; fix conflicts and then commit the result. (base) PS C:\Users\95734\Desktop\gittest> git status On branch main Your branch is ahead of 'origin/main' by 3 commits. (use "git push" to publish your local commits)
You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge)
Unmerged paths: (use "git add <file>..." to mark resolution) both modified: text1.txt
no changes added to commit (use "git add" and/or "git commit -a")
(base) PS C:\Users\95734\Desktop\gittest> git add .\text1.txt (base) PS C:\Users\95734\Desktop\gittest> git commit -m"change again" [main45e7316] change again (base) PS C:\Users\95734\Desktop\gittest> git checkout main Already on 'main' Your branch is ahead of 'origin/main' by 5 commits. (use "git push" to publish your local commits) (base) PS C:\Users\95734\Desktop\gittest> git merge dev Already up to date. (base) PS C:\Users\95734\Desktop\gittest> git status On branch main Your branch is ahead of 'origin/main' by 5 commits. (use "git push" to publish your local commits)
nothing to commit, working tree clean (base) PS C:\Users\95734\Desktop\gittest> git log --graph--pretty=oneline --abbrev-commit * 45e7316 (HEAD -> main) change again |\ | * 880c3c6 (dev) change the text2 on dev * | 7ad011f change the text1 on main |/ * 77f5bda change the text1 * e65406f dev test * c5bbf4e (origin/main) add the third file * f9ccede add another file * b8a15e1 wrote a new file