小编Rob*_*man的帖子

如何配置"git pull --ff-only"和"git merge --no-ff"

对我来说,典型的git工作流是克隆远程存储库并使用git pull来使其保持最新.我拉的时候不想要合并提交,所以我使用--ff-only选项.

我还为特色工作设立了本地分支机构.我想保留分支历史记录,所以当我将本地分支合并回我的本地克隆时,我使用--no-ff选项.

如何配置git默认使用这些选项?目前我的.gitconfig看起来像这样:

[merge]
  ff = false
[pull]
  ff = only
Run Code Online (Sandbox Code Playgroud)

但是,git pull(实际上是git fetch和git merge)似乎正在拾取合并选项,因此创建了合并.

git git-pull git-merge git-config

18
推荐指数
1
解决办法
7255
查看次数

DateTimeFormatter和SimpleDateFormat产生不同的字符串

这不是某些人认为的重复。它是关于用于格式化日期的两个标准Java类,这些类在自时期以来以相同的毫秒值生成不同的字符串。

对于自1883年某个时间点之前的纪元以来的毫秒值,SimpleDateFormat和DateTimeFormatter将产生不同的结果。由于我不明白的原因,DateTimeFormatter会产生与我期望的字符串相差将近四分钟的字符串。

这很重要,因为我正在更改一些代码以使用DateTimeFormatter而不是SimpleDateFormat。我们的输入始终是从纪元以来的毫秒数,在更改代码后,我需要将值设置为相同。

先前的代码将以毫秒为单位创建一个Date,然后使用SimpleDateFormat对其进行格式化。

新代码从毫秒创建一个Instant,然后从Instant创建一个ZonedDateTime,然后创建一个DateTimeFormatter对其进行格式化。

这是我使用JUnit4和Hamcrest编写的测试。该测试查找自5月13日15:41:25的纪元以来的毫秒数,该时间为2019年开始的每一年,并且每次倒退一年。

对于每年,它使用SimpleDateFormat和DateTimeFormatter格式化毫秒格式,然后比较结果。

@Test
  public void testSimpleDateFormatVersusDateTimeFormatter() throws Exception {
    String formatString = "EEE MMM dd HH:mm:ss zzz yyyy";
    String timeZoneCode = "America/New_York";

    ZoneId zoneId = ZoneId.of(timeZoneCode);

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatString);
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone(timeZoneCode));

    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(formatString);

    for (int year = 0; year < 200; year++) {

      long millis = getMillisSinceEpoch(2019 - year, 5, 13, 15, 41, 25, timeZoneCode);

      System.out.printf("%s%n", new Date(millis));

      // Format using a DateTimeFormatter;
      Instant instant = Instant.ofEpochMilli(millis);
      ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, zoneId); …
Run Code Online (Sandbox Code Playgroud)

java java.time

1
推荐指数
1
解决办法
61
查看次数

标签 统计

git ×1

git-config ×1

git-merge ×1

git-pull ×1

java ×1

java.time ×1