The signature is an ID justification. The email you set should be your github account.
Initialize local lib
1
git init
Suppose the project is in the folder git-demo, then under this folder, start the git bash, enter the command above, then git get authorization of the folder git-demo, and initialized the local lib.
check status
1
git status
example log:
1 2 3
On branch master //on which branch no commits yet //blank git lib nothing to commit
add a new file hello.txt under the project and input “hello world.”
1 2 3 4 5 6 7 8 9 10 11
On branch master
No commits yet
Untracked files: (use "git add <file>..." to include in what will be committed) hello.txt //hello.txt is only in the workspace, but not added in the cache, so it's not been tracked by git nothing added to commit but untracked files present (use "git add" to track)
add files to cache
1
git add [filename]
after git add hello.txt, the status:
1 2 3 4 5 6 7 8
On branch master
No commits yet
Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: hello.txt
commit the file to the local lib
1
git commit -m "log message" [filename]
Example: after git commit -m "my first commit" hello.txt, the log:
1 2 3 4 5
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it [master (root-commit) 64c69a6] hello git commit 1 file changed, 1 insertion(+) create mode 100644 hello.txt
the status:
1 2
On branch master nothing to commit, working tree clean
For example, now change the content in hello.txt to “hello world again.” to create a new version:
1 2 3 4 5 6 7 8
On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: hello.txt
no changes added to commit (use "git add" and/or "git commit -a")
after git add:
1 2 3 4
On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: hello.txt
git commit:
1 2 3
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it [master 522457b] second commit 1 file changed, 1 insertion(+), 1 deletion(-)
In the version control process, when advancing multiple tasks at the same time, you can create an independent branch for each task. Using branches means that developers separate their tasks from the main line of development, and when developing their own branches, it will not affect the main line.
explanation:
Programmer A want to add function A for the project, so it forks a branch Task A from the ver1.0 Master branch. After development, he unions Task A to the main branch, and update it to ver1.1. Then the Infra found some bugs in ver1.1, so he forks a branch Hot fix from the ver1.1 Master branch, fixing the bugs, and update the Master to ver1.2.
$ git status On branch hot-fix Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: hello.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git add hello.txt warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it
$ git commit -m "hot-fix first commit" hello.txt warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it [hot-fix 1a25fb0] hot-fix first commit 1 file changed, 1 insertion(+), 1 deletion(-)
Two different branches fixed the same position of the same file differently. In that case, Git cannot determine which one to deserve, then it causes conflict.
$ git merge hot-fix Auto-merging hello.txt CONFLICT (content): Merge conflict in hello.txt Automatic merge failed; fix conflicts and then commit the result.
$ git status On branch master 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: hello.txt
no changes added to commit (use "git add" and/or "git commit -a")
The log Automatic merge failed; fix conflicts and then commit the result. shows that the merge was failed, because master and hot-fix fixed the same file hello.txt .
The code between <<<<<<< HEAD and ======= is what the current branch has in the file, while the code between ======= and >>>>>>> hot-fix is that in the branch hot fix.
Now suppose that we’d like to keep the hot-fix version, then delete the special lines which are combined of > = <, and keep Hello fixed 222, then: