Py学习  »  Git

在Git中有局部不可推动的更改

animek sahu • 4 年前 • 768 次点击  

在Git克隆之后,为了使代码正常工作,我必须在本地进行一些更改。因此,每当我需要推送代码时,我都需要在推送之前撤消这些更改。是否有任何方法可以使某些本地更改不会显示在Git Diff中? 我不想只忽略代码的一部分完整文件。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38002
 
768 次点击  
文章 [ 4 ]  |  最新文章 4 年前
tymtam
Reply   •   1 楼
tymtam    5 年前

I suggest splitting the file/code/class into separate files.

然后有多个选项:

  1. git update-index --assume-unchanged path/to/the/file
  2. git stash 魔术与 Stash only one file out of multiple files that have changed with Git?
  3. 添加包含不想提交到git ignore的更改的文件。
Miguel Berrío
Reply   •   2 楼
Miguel Berrío    5 年前

您可以交互地决定要提交的更改。使用 git add --patch 迭代修改过的代码块并添加所需的内容。然后,您可以推动这些更改并保持本地修改。

MingMan
Reply   •   3 楼
MingMan    5 年前

不确定是否可以部分忽略文件

可以在gitignore中的配置文件中执行环境变量,然后在代码中执行以下操作

if ENV['some-environment-variable'] == 'some-value'
   //do certain things
else if  ENV['some-other-environment-variable'] == 'some-other-value'
   //do other certain things
else 
   //do nothing
end

这对你的解决方案有效吗?

ElpieKay
Reply   •   4 楼
ElpieKay    5 年前

假设你的分支是 foo . 创建新分支 bar 从它。提交可推动的更改 不可推挤的 酒吧 .

每当你想测试 的代码可以工作,运行 git rebase foo bar 首先,通过 酒吧 将被签出并更新,然后测试更新的代码 酒吧 . 如果它起作用,你可以推 .

如果 稍后用新提交更新,运行 Git Rebase Foo酒吧 再次更新 酒吧 .