git 命令行配置
程序员文章站
2024-02-17 10:15:04
...
git 配置:(master)分支的意思 -m打印信息的意思,-后面的字母可以变
1、用户配置如下:
[email protected] MINGW64 /e/uTorrent/gitProject1
$ git config --global user.name "1PeterGuo" // 配置用户名
[email protected] MINGW64 /e/uTorrent/gitProject1
$ git config --global user.password "" // 配置密码
[email protected] MINGW64 /e/uTorrent/gitProject1
$ git config --global user.email "" // 配置邮箱
2、初始化配置一个git管理库如****意初始化后的.git文件夹是隐藏的)
[email protected] MINGW64 /e/uTorrent/gitProject1
$ git init // 通过命令 git init 把这个目录变成git可以管理的仓库
Initialized empty Git repository in E:/uTorrent/gitProject1/.git/
[email protected] MINGW64 /e/uTorrent/gitProject1 (master)
$
3、创建一个文件夹hello.txt,在里面写上内容,如何查看里面内容:
[email protected] MINGW64 /e/uTorrent/gitProject1 (master)
$ cat hello.txt
1111111111111
4、如何把文件提交到gitHub上,先add再commit:
[email protected] MINGW64 /e/uTorrent/gitProject1 (master)
$ git add hello.txt
[email protected] MINGW64 /e/uTorrent/gitProject1 (master)
$ git commit -m "初次提交"
[master (root-commit) 9194e3b] 初次提交
1 file changed, 1 insertion(+)
create mode 100644 hello.txt
5、如何查看还有没有未提交的文件:
// 以下显示的是没有文件可提交
[email protected] MINGW64 /e/uTorrent/gitProject1 (master)
$ git status
On branch master
nothing to commit, working tree clean
// 以下显示的是有文件可提交,且文件名为hello.txt
[email protected] MINGW64 /e/uTorrent/gitProject1 (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: hello.txt
6、如何查看提交的记录:
[email protected] MINGW64 /e/uTorrent/gitProject1 (master)
$ git log
commit 7b5a3263fc04c880dfe6ecbab0f43436be64681c (HEAD -> master)
Author: 1PeterGuo <[email protected]>
Date: Mon Apr 1 08:46:36 2019 +0800
添加222222
commit 9194e3bc80e479edb9414f1ca8a6486c7fa6deac
Author: 1PeterGuo <[email protected]>
Date: Mon Apr 1 08:35:31 2019 +0800
初次提交
7、如何转换分支:
[email protected] MINGW64 /e/uTorrent/gitProject1 (master)
$ git checkout -b gl
Switched to a new branch 'gl'
M hello.txt
8、改变分支后,文本提示信息还是用以前的-m,要不然会报错:
[email protected] MINGW64 /e/uTorrent/gitProject1 (gl)
$ git commit -b "提交"
error: unknown switch `b'
usage: git commit [<options>] [--] <pathspec>...
-q, --quiet suppress summary after successful commit
-v, --verbose show diff in commit message template
Commit message options
-F, --file <file> read message from file
--author <author> override author for commit
--date <date> override date for commit
-m, --message <message>
commit message
-c, --reedit-message <commit>
reuse and edit message from specified commit
-C, --reuse-message <commit>
reuse message from specified commit
--fixup <commit> use autosquash formatted message to fixup specified commit
--squash <commit> use autosquash formatted message to squash specified commit
--reset-author the commit is authored by me now (used with -C/-c/--amend)
-s, --signoff add Signed-off-by:
-t, --template <file>
use specified template file
-e, --edit force edit of commit
--cleanup <default> how to strip spaces and #comments from message
--status include status in commit message template
-S, --gpg-sign[=<key-id>]
GPG sign commit
Commit contents options
-a, --all commit all changed files
-i, --include add specified files to index for commit
--interactive interactively add files
-p, --patch interactively add changes
-o, --only commit only specified files
-n, --no-verify bypass pre-commit and commit-msg hooks
--dry-run show what would be committed
--short show status concisely
--branch show branch information
--ahead-behind compute full ahead/behind values
--porcelain machine-readable output
--long show status in long format (default)
-z, --null terminate entries with NUL
--amend amend previous commit
--no-post-rewrite bypass post-rewrite hook
-u, --untracked-files[=<mode>]
show untracked files, optional modes: all, normal, no. (Default: all)
[email protected] MINGW64 /e/uTorrent/gitProject1 (gl)
$ git commit -m "提交了"
[gl c278575] 提交了
1 file changed, 1 insertion(+), 1 deletion(-)
9、如何切换回主分支,并显示分支和主分支的区别:
[email protected] MINGW64 /e/uTorrent/gitProject1 (gl)
$ cat hello.txt
1111111111111
333333333
[email protected] MINGW64 /e/uTorrent/gitProject1 (gl)
$ git checkout -b master
fatal: A branch named 'master' already exists.
[email protected] MINGW64 /e/uTorrent/gitProject1 (gl)
$ cat hello.txt
1111111111111
333333333
[email protected] MINGW64 /e/uTorrent/gitProject1 (gl)
$ git checkout master
Switched to branch 'master'
[email protected] MINGW64 /e/uTorrent/gitProject1 (master)
$ cat hello.txt
1111111111111
222222222
[email protected] MINGW64 /e/uTorrent/gitProject1 (master)
$
10、如何合并分支:(CONFLICT)冲突
[email protected] MINGW64 /e/uTorrent/gitProject1 (master)
$ git merge gl
Auto-merging hello.txt
CONFLICT (content): Merge conflict in hello.txt
Automatic merge failed; fix conflicts and then commit the result.
查看冲突后的状态:
[email protected] MINGW64 /e/uTorrent/gitProject1 (master|MERGING)
$ 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")
冲突后的文件夹样式:
(Git用<<<<<<<,=======,>>>>>>>标记出不同分支的内容,其中<<<HEAD是指主分支修改的内容,>>>>>gl 是指gl上修改的内容)
1111111111111
<<<<<<< HEAD
222222222
0000000000
=======
333333333
>>>>>>> gl
11、如果命令符变成一个“:”,如何变回原来的样子?
按Q键再确认就可以了,$
12、查看有哪些分支!
[email protected] MINGW64 /e/uTorrent/gitProject1 (master)
$ git branch
gl
* master
13、删除分支
[email protected] MINGW64 /e/uTorrent/gitProject1 (master)
$ git branch -d gl
Deleted branch gl (was 2af4987).
[email protected] MINGW64 /e/uTorrent/gitProject1 (master)
$ git branch
* master
上一篇: php中随机取出数组中不重复的值
下一篇: 简单数据结构 之 单调栈&&单调队列