GIT安装步骤记录以及Git 常用命令,忽略文件,推送本地代码到仓库示例以及常用报错解决

人生苦短,我们要:

image.png

下载

下载地址

git-scm.com

gitforwindows.org

安装(凡是下面没有给出图片的,都按默认选项就行)

选择安装组件

调整你的 path 环境变量

第一种是仅从 Git Bash 使用 Git。

第二种是从命令行以及第三方软件进行 Git。

第三种是从命令提示符使用 Git 和可选的 Unix 工具。

选择HTTPS后端传输

在具有企业管理证书的组织中要使用安全通道。一般都用第一个就OK了~

添加成功以后

推送本地代码到仓库示例以及报错解决

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\jin_files\code\pwa\service_worker> 
PS C:\jin_files\code\pwa\service_worker> git init 
Initialized empty Git repository in C:/jin_files/code/pwa/service_worker/.git/
PS C:\jin_files\code\pwa\service_worker> git add README.md
On branch master

Initial commit

  (use "git add <file>..." to include in what will be committed)
        index.html

nothing added to commit but untracked files present (use "git add" to track)
PS C:\jin_files\code\pwa\service_worker> git remote add origin https://gitee.com/tangdd369098655/service_worker.git
error: src refspec master does not match any
error: failed to push some refs to 'https://gitee.com/tangdd369098655/service_worker.git'
PS C:\jin_files\code\pwa\service_worker> git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        index.html

nothing added to commit but untracked files present (use "git add" to track)
PS C:\jin_files\code\pwa\service_worker> git add index.html
PS C:\jin_files\code\pwa\service_worker> git status
On branch master

No commits yet
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   index.html

PS C:\jin_files\code\pwa\service_worker> git commit -m "initial commit"
[master (root-commit) a9cdf97] initial commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 index.html
On branch master
PS C:\jin_files\code\pwa\service_worker> git push
fatal: The current branch master has no upstream branch.

    git push --set-upstream origin master

PS C:\jin_files\code\pwa\service_worker> git remote origin
error: Unknown subcommand: origin
usage: git remote [-v | --verbose]
   or: git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url>
   or: git remote rename <old> <new>
   or: git remote remove <name>
   or: git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
   or: git remote [-v | --verbose] show [-n] <name>
   or: git remote prune [-n | --dry-run] <name>
   or: git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]
   or: git remote set-branches [--add] <name> <branch>...
   or: git remote get-url [--push] [--all] <name>
   or: git remote set-url [--push] <name> <newurl> [<oldurl>]
   or: git remote set-url --add <name> <newurl>
   or: git remote set-url --delete <name> <url>

    -v, --verbose         be verbose; must be placed before a subcommand

PS C:\jin_files\code\pwa\service_worker> gie remote
gie : The term 'gie' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:1
+ gie remote
+ ~~~
    + CategoryInfo          : ObjectNotFound: (gie:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\jin_files\code\pwa\service_worker> git remote
origin
PS C:\jin_files\code\pwa\service_worker> git remote -v
origin  https://gitee.com/tangdd369098655/service_worker.git (fetch)
origin  https://gitee.com/tangdd369098655/service_worker.git (push)
PS C:\jin_files\code\pwa\service_worker>  git push --set-upstream origin master
info: detecting host provider for 'https://gitee.com/'...
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcmcore-tlsverify for more information.
info: detecting host provider for 'https://gitee.com/'...
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcmcore-tlsverify for more information.
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 218 bytes | 218.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.2]
To https://gitee.com/tangdd369098655/service_worker.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
PS C:\jin_files\code\pwa\service_worker>

附录:Git 常用命令

初始化版本库,并提交到远程服务器端—名称为origin的远程服务器库

mkdir WebApp
cd WebApp
git init 本地初始化
touch README
git add README 添加文件
git commit -m 'first commit'
git remote add origin git@github.com:AAA/myCode.git
git branch 查看本地所有分支
git status 查看当前状态 
git commit 提交 
git branch -a 查看所有的分支
git branch -r 查看远程所有分支
git commit -am "init" 提交并且加注释 
git push origin master 将文件给推到服务器上 
git remote show origin 显示远程库origin里的资源 
git push origin master:develop
git push origin master:hb-dev 将本地库与服务器上的库进行关联 
git checkout --track origin/dev 切换到远程dev分支
git branch -D master develop 删除本地库develop
git checkout -b dev 建立一个新的本地分支dev
git merge origin/dev 将分支dev与当前分支进行合并
git checkout dev 切换到本地dev分支
git remote show 查看远程库
git rm 文件名(包括路径) 从git中删除指定文件
git clone git://github.com/aaa/aaaa.git 从服务器上将代码给拉下来
git config --list 看所有用户
git ls-files 看已经被提交的
git rm [file name] 删除一个文件
git commit -a 提交当前repos的所有的改变
git add [file name] 添加一个文件到git index
git commit -v 当你用-v参数的时候可以看commit的差异
git commit -m "This is the message describing the commit" 添加commit信息
git commit -a -a是代表add,把所有的change加到git index里然后再commit
git commit -a -v 一般提交命令
git log 看你commit的日志
git diff 查看尚未暂存的更新
git rm a.a 移除文件(从暂存区和工作区中删除)
git rm --cached a.a 移除文件(只从暂存区中删除)
git commit -m "remove" 移除文件(从Git中删除)
git rm -f a.a 强行移除修改后文件(从暂存区和工作区中删除)
git diff --cached 或 $ git diff --staged 查看尚未提交的更新
git remote add origin git@github.com:username/Hello-World.git
git push origin master 将本地项目给提交到服务器中
git pull 本地与服务器端同步
git push (远程仓库名) (分支名) 将本地分支推送到服务器上去。
git push origin serverfix:awesomebranch
git fetch 相当于是从远程获取最新版本到本地,不会自动merge
git commit -a -m "log_message" (-a是提交所有改动,-m是加入log信息) 本地修改同步至服务器端 :
git branch branch_0.1 master 从主分支master创建branch_0.1分支
git branch -m branch_0.1 branch_1.0 将branch_0.1重命名为branch_1.0
git checkout branch_1.0/master 切换到branch_1.0/master分支
du -hs
git branch 删除远程branch
git push origin :branch_remote_name
git branch -r -d branch_remote_name

忽略某个文件夹

如果已经提交过的文件或者文件夹怎么办?此时更改.gitignore文件对已经提交的文件是无效的

编辑.gitignore文件。
然后如果是单个文件,可以使用如下命令从仓库中删除:
git rm --cached logs/xx.log
如果是整个目录:
git rm --cached -r logs
如果文件很多,那么直接
git rm --cached -r .
如果提示某个文件无法忽略,可以添加-f参数强制忽略。
git rm -f --cached logs/xx.log
然后
git add .
git commit -m "Update .gitignore"

使用.gitignore忽略文件或者文件夹参考来源 https://blog.csdn.net/toopoo/article/details/88660806
常用命令部分参考来源 https://www.cnblogs.com/kenshinobiy/p/4543976.html

在这里插入图片描述

欢迎大家指出文章需要改正之处~
学无止境,合作共赢
在这里插入图片描述

欢迎路过的小哥哥小姐姐们提出更好的意见哇~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值