正如前面所说,tree也是一串HASH值,这串HASH存储的是元信息。用来表示目录层次关系的。这和一般的SCM系统中是不一样,一般的SCM中目录同文件是一样的保存为版本对象的。
[root@wrlinux3 mygit]# git commit -a -m "init commit"
[master (root-commit) 4cfc524] init commit
Committer: ROOT root
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
对应的操作记录如下:
[root@wrlinux3 mygit]# git checkout -b iss53
Switched to a new branch 'iss53'
[root@wrlinux3 mygit]# vi main.c
[root@wrlinux3 mygit]# git commit -a -m 'add new variable to calculate the value on branch [iss53]'
[iss53 2f1f64e] add new variable to calculate the value on branch [iss53]
Committer: ROOT root
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the> git commit --amend --reset-author
1 file changed, 5 insertions(+), 1 deletion(-)
[root@wrlinux3 mygit]# git checkout master
Switched to branch 'master'
[root@wrlinux3 mygit]# git checkout -b 'hotfix'
Switched to a new branch 'hotfix'
[root@wrlinux3 mygit]# git branch
* hotfix
iss53
master
testing
[root@wrlinux3 mygit]# cd testdir/
[root@wrlinux3 testdir]# vi test.c
[root@wrlinux3 testdir]# git commit -a -m 'fixed the issue"
[root@wrlinux3 testdir]# cd ..
> ls
> ^C
[root@wrlinux3 testdir]# cd ..
[root@wrlinux3 mygit]# ls
main.c README testdir
[root@wrlinux3 mygit]# git commit -a -m 'fixed the issue"
> ^C
[root@wrlinux3 mygit]# git commit -a -m 'fixed the issue'
[hotfix 85412f9] fixed the issue
Committer: ROOT root
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the> git commit --amend --reset-author
1 file changed, 4 insertions(+), 1 deletion(-)
[root@wrlinux3 mygit]# git checkout master
Switched to branch 'master'
[root@wrlinux3 mygit]# git merge hotfix
Updating 4cfc524..85412f9
Fast-forward
testdir/test.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[root@wrlinux3 mygit]# git branch -d hotfix
Deleted branch hotfix (was 85412f9).
[root@wrlinux3 mygit]# git branch
iss53
* master
testing
[root@wrlinux3 mygit]# vi testdir/test.c
[root@wrlinux3 mygit]# git checkout master
Already on 'master'
[root@wrlinux3 mygit]# git merge iss53
Merge made by the 'recursive' strategy.
main.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[root@wrlinux3 mygit]# git merge iss53
Already up-to-date.
[root@wrlinux3 mygit]#
通过GIT进行合并,因为是基本文本方式合并,可能不与CC中图形化直观,但是一定要注意两点,一点是DIFF工具可改,二点是MERGE前的工作区应该是干净的。当提示一些CONFLIC时需要手工打这些文件进行修改。
[root@wrlinux3 mygit]# git mergetool
No files need merging
[root@wrlinux3 mygit]# git checkout testing
Switched to branch 'testing'
[root@wrlinux3 mygit]# ls
main.c README testdir
[root@wrlinux3 mygit]# vi main.c
[root@wrlinux3 mygit]# git commit -a -m "test comments"
[testing d2569cb] test comments
Committer: ROOT root
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the> git commit --amend --reset-author
1 file changed, 1 insertion(+)
[root@wrlinux3 mygit]# git checkout master
Switched to branch 'master'
[root@wrlinux3 mygit]# git mergetool
No files need merging
[root@wrlinux3 mygit]# git merge testing
Auto-merging main.c
CONFLICT (content): Merge conflict in main.c
Automatic merge failed; fix conflicts and then commit the result.
[root@wrlinux3 mygit]# git status
# On branch master
# Unmerged paths:
# (use "git add/rm ..." as appropriate to mark resolution)
#
# both modified: main.c
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@wrlinux3 mygit]# git merge testing
error: 'merge' is not possible because you have unmerged files.
hint: Fix them up in the work tree,
hint: and then use 'git add/rm ' as
hint: appropriate to mark resolution and make a commit,
hint: or use 'git commit -a'.
fatal: Exiting because of an unresolved conflict.
[root@wrlinux3 mygit]# git status
# On branch master
# Unmerged paths:
# (use "git add/rm ..." as appropriate to mark resolution)
#
# both modified: main.c
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@wrlinux3 mygit]# git commit -a -m "commit stat"
[master 5e453fa] commit stat
Committer: ROOT root
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the> git commit --amend --reset-author
[root@wrlinux3 mygit]# git st
# On branch master
nothing to commit (working directory clean)
前面讲了一些通用的分支操作,通过创建分支、合并分支并最终形成一个稳定的版本的过程,这个过程也是我们常见的SCM的管理职责,目前SCM人员需要制定主分支、开发分支、特性分支,通过管控这些分支来保证整个产品的质量的稳定。如下图所示:
对应的操作记录如下:
[root@wrlinux3 mygit]# git branch experiment
[root@wrlinux3 mygit]# git branch
experiment
* master
[root@wrlinux3 mygit]# git checkout -b experiment
fatal: A branch named 'experiment' already exists.
[root@wrlinux3 mygit]# git checkout -B experiment
Switched to and reset branch 'experiment'
[root@wrlinux3 mygit]# vi main.c
[root@wrlinux3 mygit]# git commit -a -m 'commit on experiment'
[experiment 774b7ee] commit on experiment
Committer: ROOT root
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the> git commit --amend --reset-author
1 file changed, 2 insertions(+), 3 deletions(-)
[root@wrlinux3 mygit]# git checkout master
Switched to branch 'master'
[root@wrlinux3 mygit]# vi main.c
[root@wrlinux3 mygit]# git commit -a -m 'commit on master'
[master cbe0f99] commit on master
Committer: ROOT root
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the> git commit --amend --reset-author
1 file changed, 1 insertion(+), 2 deletions(-)
[root@wrlinux3 mygit]# gitk
[root@wrlinux3 mygit]# vi main.c
[root@wrlinux3 mygit]# git commit -a -m 'commit on master more'
[master 8f20d8c] commit on master more
Committer: ROOT root
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the> git commit --amend --reset-author
1 file changed, 1 insertion(+)
[root@wrlinux3 mygit]# git checkout experiment
Switched to branch 'experiment'
[root@wrlinux3 mygit]# git rebase master
It seems that there is already a rebase-apply directory, and
I wonder if you are in the middle of another rebase. If that is the
case, please try
git rebase (--continue | --abort | --skip)
If that is not the case, please
rm -fr /work/bongos/mygit/.git/rebase-apply
and run me again. I am stopping in case you still have something
valuable there.
[root@wrlinux3 mygit]# rm -fr /work/bongos/mygit/.git/rebase-apply
[root@wrlinux3 mygit]# git rebase master
First, rewinding head to replay your work on top of it...
Applying: commit on experiment
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging main.c
CONFLICT (content): Merge conflict in main.c
Failed to merge in the changes.
Patch failed at 0001 commit on experiment
When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To check out the original branch and stop rebasing run "git rebase --abort".
[root@wrlinux3 mygit]# vi main.c
[root@wrlinux3 mygit]# git rebase --continue
main.c: needs merge
You must edit all merge conflicts and then
mark them as resolved using git add
[root@wrlinux3 mygit]# git add .
[root@wrlinux3 mygit]# git rebase --continue
Applying: commit on experiment
[root@wrlinux3 mygit]# git st
# On branch experiment
nothing to commit (working directory clean)
[root@wrlinux3 mygit]# gitk
[root@wrlinux3 mygit]# git branch
* experiment
master
[root@wrlinux3 mygit]#