github拉取项目,其中的.sh文件如何避免在linux执行报错

我的项目目录中有.sh文件,我将项目拉取到windows环境,修改代码,然后上传代码到仓库,在linux机器上拉取代码执行,中间有两个问题:

1.如果我把项目代码拉取到windows机器上,但是不修改.sh文件,修改其他代码文件,那么上传之后,在linux上拉取执行.sh会报错么

2.如果windows修改了.sh,到linux下执行肯定会报错,那在windows传到github这一过程中能不能通过什么脚本来控制.sh自动修改文件格式

image.png

阅读 2.1k
1 个回答

About line endings

Every time you press return on your keyboard you insert an invisible character called a line ending. Different operating systems handle line endings differently.

When you're collaborating on projects with Git and GitHub, Git might produce unexpected results if, for example, you're working on a Windows machine, and your collaborator has made a change in macOS.

You can configure Git to handle line endings automatically so you can collaborate effectively with people who use different operating systems.

Global settings for line endings

The git config core.autocrlf command is used to change how Git handles line endings. It takes a single argument.

On Windows, you simply pass true to the configuration. For example:

$ git config --global core.autocrlf true
# Configure Git to ensure line endings in files you checkout are correct for Windows.
# For compatibility, line endings are converted to Unix style when you commit files.

看起来是 Line ending 的问题。截图里那个 ^M ,就是 Windows 换行符(CRLF)的一部分(CR)。上面是从 github 文档 上摘了一点出来。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题