Git easy to operate finishing

Git simple operation flow
1.git mounting
the sudo the install APT-GET Git
2.git initialize
the init Git
3.git arranged
Git config --list
4.git submodule
git submodule add url (path / name_alias )
use the default tracking command is master branch, may be used
git config -f .gitmodules submodule.DbConnector.branch stable
change branch
5. submit the changes
(1) in first sub-module cd path, after performing the main git add engineering, the commit Git, Git Push
(2) If you set the configuration options in the main project:
git config status.submodulesummary 1
git will display a summary of changes to your sub-module of
the main projects submitted, use the following command will take the initiative to enter the sub-module submission
git push --recurse-submodules = check
or:
Git = Push --recurse-ON-Demand submodules

6. The updating sub-module
git submodule update --remote (--init --recursive)
When you run git submodule update --remote, Git default will try to update all sub-modules, so if there are a lot of sub-modules, you can pass the name of the sub-modules you want to update
7. clones contain engineered sub-module
git clone url alias -name
Git submodule local configuration file to initialize the init
git submodule update submodule-name item from the fetch all the data and detects the appropriate parent project submission listed.
Or:
git clone --recursive url option, it will automatically initialize and update the warehouse in each sub-module

8. file operations (local / remote database: add, delete, change)
8.1 increase (filed cache)
Git git the Add & commit -m "commit-message"
or:
Git the commit -a -m "the commit-the Message"
8.2 delete
(1) git rm xxx [-f ]
can do this work with git rm command and removed from the joint working directory the specified file, once submitted, the file is no longer included in the version management, and if modified and has been put before you remove the staging area, then you must use force delete option -f (translation: force the first letter ). This is a safety feature to prevent accidental deletion of data has not yet added to the snapshot, such data can not be restored Git.
(2) Delete xxx buffer only, does not affect the contents of the library
git rm --cached xxx
can use wildcards, delete some files to compile
8.3 rename / move files
$ git mv file_from file_to
in fact, run git mv is equivalent to run the following three commands:
$ mv README.md the README
$ git RM README.md
$ git the Add the README
8.4 submit
$ git the Add xxx
$ git the commit -m "message"
or:
$ git the commit -a -m "message"

(1) modify the information submitted
$ git commit --amend -m "xxx"
sometimes we submitted over only to find several missing file is not added, or submit the information was wrong. At this point, you can run the command with the submitted try to resubmit --amend option, you will have a final submission - second submission will replace the results of the first submission of

documents (2) cancel the staging of
prompt use git reset HEAD <file> ... to cancel the staging, although --hard plus option when calls can make git reset a dangerous command (translation: progress may lead to loss of all current working directory!), without the option to git reset call is not dangerous - it only modifies the staging area.
git reset the hash value [--hard] to revert to a particular submission


undo changes to a file (3)
git Checkout - [File] is a dangerous command, which is very important. You make any changes to that file will be gone - you just copied another file to overwrite it. Unless you really do not want to know
That document, otherwise do not use this command.
8.5 View staging and non-staging changes
(1) Status git
git Status has been listed under the file name in the appropriate fields by way of answering this question, what specific line changed git diff will show through the patch file format
( 2) git diff
when you need to see when any differences between the two trees you can use the git diff command. This command can view your work environment and your differences in the temporary area (git diff default practice), you staging area and the difference between your last commit (git diff --staged), or compare two records submitted differences (git diff master branchB).
To view the document has not been updated staging what part, without the direct input parameter git diff:
This command is to compare the differences between files and snapshot staging area in the current working directory, that is, after the modification has not scratch up changes in content. To see the staging of the next submission will be added to the contents, you can use git diff --cached command. (Git 1.6.1 and later also allows the use git diff --staged, the effect is the same, but easier to remember something.)
Please note, git diff itself shows only the temporary changes yet, not since the last submission since all changes made. After so sometimes you scratch once all updated files, run git diff, but nothing is for this reason.
8.6 View submit information
Git log View submit information
a common option is -p, to display the contents of each submission differences. You can also add -n to display only the most recent n times submitted:

9.分支操作(切换,合并)
分支创建 切换,远程分支, 删除(本地/远程),提交,拉取,合并
9.1 创建分支
git branch xxx-branch
9.2 切换分支
git checkout xxx-branch或:git checkout -b xxx-branch
当本地有未提交的修改内容时,切换分支会报错,可以考虑提交或
储藏修改 git stash (注:当切换分支后,并不会保存修改的内容)
9.3 创建远程分支
Git add xxx & git commit -m "message" & git push origin xxx-branch
9.4 拉取
git fench xxx-branch
git merge origin xxx-branch
git fetch 命令从服务器上抓取本地没有的数据时,它并不会修改工作目录中的内容。 它只会获取数据然后让你自己手动合并。
或:
git pull origin xxx-branch
git pull 在大多数情况下它的含义是一个 git fetch 紧接着一个git merge 命令。

9.5 提交
提交到本地:git commit xxx_branch
提交到远程仓库:git push origin xxx-branch
9.6 合并
切换到其他分支,git merge xxx-branch (建议通过github网页进行合并,操作简单明了)

9.7 删除
删除本地分支:git branch -d xxx-branch
删除远程分支:git push origin --delete xxx-branch
10 打标签/发布

10.1 查看标签

git tag
git tag -l '通配符'
10.2 创建标签
Git 使用两种主要类型的标签:轻量标签(lightweight)与附注标签(annotated)。一个轻量标签很像一个不会改变的分支 - 它只是一个特定提交的引用。然而,附注标签是存储在 Git 数据库中的一个完整对象。 它们是可以被校验的;其中包含打标签者的名字、电子邮件地址、日期时间;还有一个标签信息;并且可以使用 GNU Privacy Guard (GPG)签名与验证。 通常建议创建附注标签,这样你可以拥有以上所有信息;但是如果你只是想用一个临时的标签,或者因为某些原因不想要保存那些信息,轻量标签也是可用的。
10.2.1 附注标签
在 Git 中创建一个附注标签是很简单的。 最简单的方式是当你在运行 tag 命令时指定 -a 选项

10.2.2 轻量标签

10.3 后期打标签

 10.4 查看标签

git tag 查看标签
git show xxx-tag 查看标签信息
10.5 共享标签
默认情况下,git push 命令并不会传送标签到远程仓库服务器上。 在创建完标签后你必须显式地推送标签到共享服务器上。 这个过程就像共享远程分支一样,你可以运行 git push origin [tag-name]。

10.6删除标签

要删除掉你本地仓库上的标签,可以使用命令 git tag -d <tagname>。例如,可以使用下面的命令删除掉一个轻量级标签

10.7 切换至标签

如果你想查看某个标签所指向的文件版本,可以使用 git checkout 命令,虽然说这会使你的仓库处于“分离头指针(detacthed HEAD)”状态——这个状态有些不好的副作用,慎用

注意:

1. 对于含有子模块的工程,当需要修改子模块时应当查看当前的提交哈希值(用于确定当前使用的分支),否则,提交时会造成一些文件的烦恼。
附录:
1. git 操作手册 https://files-cdn.cnblogs.com/files/rain123/pro-git_v2.1.24.zip

 

Guess you like

Origin www.cnblogs.com/rain123/p/11299404.html