[git] HOWTO-work with git

查看版本号

cat .git/refs/heads/cn/develop


添加一个远程地址

git remote add


显示所有的远程地址 

git remote -v


查看远程服务端

git remote show origin


创建新分支并追中远程地址中的分支

git checkout --track  remoteaddr/remotebranch

等同于git checkout -b remotebranch remoteaddr/remotebranch


创建不相同的分支并追踪远程分支

git checkout -b SF/rc --track us/rc


显示追踪情况

git remote show origin


创建远程端

以head的内容在远程创建newbranch

git push origin head:newbranch

git push origin head:feature/newbranch


删除远程端.

以空内容在覆盖远程newbranch

git push origin :newbranch

git push origin --delete path1/path2


单独提交某个分支

git push origin cn/porting/rc_clean

---------------TAG START----------------

本地创建TAG

git tag -a SOMETAG  -m "create tag for SOMEREASON"


本地查看TAG

git tag -l


PUSH TAG到服务器

git push --tags


删除本地TAG

git tag -d TAG


checkout tag

git checkout SOMETAG, git checkout -b SOMETAG.

----------------TAG END------------------



----------------MERGE--------------------

merge经常会出现太多conflict甚至显示不全的时候, 这个时候

git config --list

查找 diff.renamelimit=0的设置

git config diff.renamelimit=13191

----------清理----------

删除 # 开头 含有Trans的没有版本管理里的文件, !!!!慎用!!!!!

git status |  grep '#' | grep 'Trans' |  cut -b 2,3- | xargs rm -r


### Git CRLF to LF Conversion Configuration and Solutions In environments where developers work across different operating systems (Windows, Linux, macOS), line ending differences can cause issues when sharing code through Git repositories. Windows traditionally uses Carriage Return Line Feed (`\r\n` or CRLF) while Unix-like systems including Linux and macOS use only Line Feed (`\n` or LF). To address this issue within Git projects, specific configurations help ensure consistency. To configure Git so that it converts all carriage returns from CRLF format used by Windows into the simpler LF format preferred on Unix-based platforms during commits: #### Setting Up Core Autocrlf Globally A global setting ensures consistent behavior across multiple local repositories without needing individual adjustments per project. ```bash git config --global core.autocrlf input ``` This command instructs Git to convert CRLFs to LFs upon committing files but leaves existing line endings untouched in checked-out content[^1]. For users who exclusively operate within Unix/Linux/macOS ecosystems and wish to enforce strict LF usage both ways—when checking out as well as committing changes—the following alternative may be more appropriate: ```bash git config --global core.eol lf git config --global core.autocrlf false ``` These settings prevent any automatic conversion of line endings at checkout time yet still allow manual specification via `.gitattributes`. #### Using .gitattributes File for Fine-grained Control The repository-specific file named `.gitattributes` allows defining rules about how certain types of files should handle end-of-line characters independently of user preferences set globally. This approach provides finer control over which files undergo transformation based on patterns matching filenames or paths relative to root directory. An example entry might look like this inside your `.gitattributes`: ```plaintext * text=auto eol=lf *.sh text eol=lf *.bat text eol=crlf ``` Such entries tell Git what kind of treatment each type of file receives regarding its EOL style; here `text=auto` means let Git decide automatically whether a file contains textual data suitable for normalization according to platform conventions before applying specified `eol=` directive explicitly stating desired output form after processing. By implementing these strategies, teams collaborating remotely can maintain uniformity concerning their source codes' formatting aspects despite varying development setups they employ locally.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值