読者です 読者をやめる 読者になる 読者になる

by shigemk2

当面は技術的なことしか書かない

ディレクトリの中のファイルの差分を知る

Linux

rオプションをつける。

diff -r dir1 dir2
$ diff -r 40 411
diff -r 40/lib/codebreaker/game.rb 411/lib/codebreaker/game.rb
22c22,24
<       @output.puts '+'*exact_match_count(guess) + '-'*number_match_count(guess)
---
>       marker = Marker.new(@secret)
>       @output.puts '+'*marker.exact_match_count(guess) +
>                    '-'*marker.number_match_count(guess)

eオプション。色がつかないのでわけがわからない。

$ diff -er 40 411
diff -er 40/lib/codebreaker/game.rb 411/lib/codebreaker/game.rb
46a

.
41,42c
      def exact_match?(guess, index)
        guess[index] == @secret[index]
      end

      def number_match?(guess, index)
        @secret.include?(guess[index]) && !exact_match?(guess, index)
      end
.

cオプション。差分がまとまってしまうので、これも微妙に見辛い

$ diff -cr 40 411
diff -cr 40/lib/codebreaker/game.rb 411/lib/codebreaker/game.rb
*** 40/lib/codebreaker/game.rb	2012-09-14 04:10:28.000000000 +0900
--- 411/lib/codebreaker/game.rb	2012-09-14 04:10:28.000000000 +0900
***************
*** 19,46 ****
      end

      def guess(guess)
!       @output.puts '+'*exact_match_count(guess) + '-'*number_match_count(guess)
      end

!     def exact_match_count(guess)
!       (0..3).inject(0) do |count, index|
!         count + (exact_match?(guess, index) ? 1 : 0)
        end
-     end

!     def number_match_count(guess)
!       (0..3).inject(0) do |count, index|
!         count + (number_match?(guess, index) ? 1 : 0)
        end
-     end

!     def exact_match?(guess, index)
!       guess[index] == @secret[index]
!     end

!     def number_match?(guess, index)
!       @secret.include?(guess[index]) && !exact_match?(guess, index)
      end
    end
  end

--- 19,55 ----
      end

      def guess(guess)
!       marker = Marker.new(@secret)
!       @output.puts '+'*marker.exact_match_count(guess) +
!                    '-'*marker.number_match_count(guess)
      end

!     class Marker
!       def initialize(secret)
!         @secret = secret
        end

!       def exact_match_count(guess)
!         (0..3).inject(0) do |count, index|
!           count + (exact_match?(guess, index) ? 1 : 0)
!         end
        end

!       def number_match_count(guess)
!         (0..3).inject(0) do |count, index|
!           count + (number_match?(guess, index) ? 1 : 0)
!         end
!       end

!       def exact_match?(guess, index)
!         guess[index] == @secret[index]
!       end
!
!       def number_match?(guess, index)
!         @secret.include?(guess[index]) && !exact_match?(guess, index)
!       end
      end
    end
  end

yオプション。色ついてないから横並びだと分かりにくい

$ diff -yr 40 411
diff -yr 40/bin/codebreaker 411/bin/codebreaker
#!/usr/bin/env ruby                                             #!/usr/bin/env ruby
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)      $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'codebreaker'                                           require 'codebreaker'

game = Codebreaker::Game.new(STDOUT)                            game = Codebreaker::Game.new(STDOUT)
game.start                                                      game.start
diff -yr 40/features/codebreaker_starts_game.feature 411/features/codebreaker_starts_game.feature
Feature: code-breaker starts game                               Feature: code-breaker starts game

diff - ファイルの差異の表示 - 会津大学UNIXウィキ

gitっぽく見れないものか。