Git官网上有code school, 跟着做,以下是具体的记录:
1. 初始化
git init//Initialized empty Git repository in /.git/
查看是否有文件增加,修改等(先新建一个文件octocat.txt)
git status
//# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# octocat.txt
nothing added to commit but untracked files present (use "git add" to track)
git add octocat.txt
//Nice job, you've added octocat.txt to the Staging Area
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: octocat.txt
5. 提交更改
git commit -m "Add cute octocat story"
//
master (root-commit) 20b5ccd] Add cute octocat story
1 file changed, 1 insertion(+)
create mode 100644 octocat.txt
git add '*.txt'
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: blue_octocat.txt
# new file: octofamily/baby_octocat.txt
# new file: octofamily/momma_octocat.txt
# new file: red_octocat.txt
8. git commit -m 'Add all the octocat txt files'
//
[master 3852b4d] Add all the octocat txt files
4 files changed, 4 insertions(+)
create mode 100644 blue_octocat.txt
create mode 100644 octofamily/baby_octocat.txt
create mode 100644 octofamily/momma_octocat.txt
create mode 100644 red_octocat.txt
git log
//
commit 3852b4db1634463d0bb4d267edb7b3f9cd02ace1
Author: Try Git <try_git@github.com>
Date: Sat Oct 10 08:30:00 2020 -0500
Add all the octocat txt files
commit b652edfd888cd3d5e7fcb857d0dabc5a0fcb5e28
Author: Try Git <try_git@github.com>
Date: Sat Oct 10 08:30:00 2020 -0500
Added cute octocat story
git remote add origin https://github.com/try-git/try_git.git
git push -u origin master
//Branch master set up to track remote branch master from origin.
//he name of our remote is origin and the default local branch name is master.
//The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do.
git pull origin master
//We can check for changes on our GitHub repository and pull down any new changes
Updating 3852b4d..3e70b0f
Fast-forward
yellow_octocat.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 yellow_octocat.txt
git diff HEAD
//the diff of our most recent commit, which we can refer to using the HEAD pointer
diff --git a/octocat.txt b/octocat.txt
index 7d8d808..e725ef6 100644
--- a/octocat.txt
+++ b/octocat.txt
@@ -1 +1 @@
-A Tale of Two Octocats
+[mA Tale of Two Octocats and an Octodog
14. git add octofamily/octodog.txt
15. 查看暂存区的diff
git diff --stageddiff --git a/octofamily/octodog.txt b/octofamily/octodog.txt
new file mode 100644
index 0000000..cfbc74a
--- /dev/null
+++ b/octofamily/octodog.txt
@@ -0,0 +1 @@
+[mwoof
git reset octofamily/octodog.txt
//git reset did a great job of unstaging octodog.txt, but you'll notice that he's still there. He's just not staged anymore.
git checkout -- octocat.txt
git branch clean_up
git checkout clean_up
git rm '*.txt'
//git rm command which will not only remove the actual files from disk, but will also stage the removal of the files for us.
21. git commit -m "Remove all the cats"
22. git checkout master
git merge clean_up
git branch -d clean_up
git push
To https://github.com/try-git/try_git.git
3e70b0f..fdfa227 master -> master