PHOENIX -- The Diamondbacks understand what they are up against entering the second half of the season, and their comeback victory against San Francisco on Saturday was a step in the right direction.

Welington Castillo's three-run homer in the eighth inning put the finishing touches on a four-run comeback for an exhilarating 6-5 victory, snapping a six-game losing streak.

As for something to build on as the teams prepare for the final game of a three-game homestand, time will tell.

"I hope so," said Arizona first baseman Paul Goldschmidt, who made a lunging stop with a runner on first base to preserve reliever Jake Barrett's first major league victory and Brad Ziegler's 17th save for the final out Saturday.

"You'd like to say yes, but who knows if you can. You show up tomorrow and it is zero-zero and it doesn't really matter that much. We need the win, just because we know how far back we are from San Fran and even in the wild card, so any win is going to be big. Hopefully the momentum carries over, but I know they are not going to be fazed by it.

"They are fine coming off losses, and it is not like if we would have lost we would have showed up and been hanging our heads tomorrow. Hopefully we can win the series."

The D-backs (37-46) will send left-hander Robbie Ray against Giants right-hander Albert Suarez in the finale of the three-game series at Chase Field on Sunday.

Arizona's victory Saturday was the first by the home team in the first 10 games of the season series. The Diamondbacks swept a four-game series at AT&T Park on April 18-21 before the Giants swept a four-gamer series at Chase Field on May 12-15. The Giants won the opener of this series Friday, coming back from two three-run deficits in a 5-4 victory.

"That is one we let get away," San Francisco manager Bruce Bochy said Saturday.

Castillo has homered in two consecutive games and has hit four of his 10 homers against the Giants this season. He had seven in his first 21 games before going 28 games without one, connecting again June 17.

Asked if his homers come in bunches, Castillo drew chuckles when he said, "That's what it looks like. I've been feeling good lately. I know I went through a tough moment. I don't worry about my hitting. I know I can hit a little bit. Just time, and it's going to come."

Arizona third baseman Jake Lamb had two hits and a walk Saturday and is close to becoming the fourth player (five occurrences) in franchise history to have 20 doubles and 20 homers before the All-Star break. Lamb hit his 19th double Saturday and has 18 homers after hitting one in each of the three previous games. Only Paul Goldschmidt (twice), Matt Williams and Jay Bell have done it.

Ray (4-7) threw six shutout innings for his first victory of the season at San Francisco on April 19, and he is 1-0 with a 1.64 ERA in two career starts against the Giants. He averages 10.42 strikeouts per nine innings, seventh highest among NL starters and third highest among left-handers.

Suarez (3-1) will make his sixth start Sunday and also has made six relief appearances. He took Matt Cain's spot in the starting rotation when Cain went out with a right hamstring strain. He has a 4.39 ERA in five starts and will gave the Diamondbacks for the first time.

SI Apps
We've Got Apps Too
Get expert analysis, unrivaled access, and the award-winning storytelling only SI can provide - from Peter King, Tom Verducci, Lee Jenkins, Seth Davis, and more - delivered straight to you, along with up-to-the-minute news and live scores.