Sourcetree Diff Against Current

broken image


Go to Preferences Diff Viewer Merge Tool and click the Advanced button. In the popup, type.unity in the extension field. In the External Program field type: merge -p%base%theirs%mine%merged Then, follow the same procedure to add the.prefab extension. Go to Preferences Merge Tools and click the. Fixed changing view in diff not updating files under folders; Fixed file list not clearing when search is empty; Nested folders in bookmarks view now will always have unique names; SourceTree 3.2.2 18 July 2019 Changes. Added dark theme and revised the current light theme; Added automatic high-contrast mode detection, and fixed many high. Comparing specific commits or right clicking a branch and 'Diff against current' works in a pinch, except it is a lot to wade through when there are several files involved in changes between commits, and all you need is to find out the history of one single file and compare it back to a certain point.

While working with Git it is often required to check the changes between different areas.

Probably everyone knows the git diff, that shows the changes between the Working Directory and the Staging Area (git diffunstaged).

But it is also often needed to shows the changes between the Staging Area and the HEAD (git diffstaged) or between the Working Directory and the HEAD (git diffstaged and unstaged).

Cool Tip: Did something wrong? Want to undo everything? You can easily revert all changes back to the last commit! Read more →

Git – Diff Staged and Unstaged Files

First of all it is required to clearly understand the meaning of the following terms:

Working Directory – files in a current local directory that you are working on.

Staging Area (aka. cache, index) – is a temporary area where you add files with git add command.

HEAD – is a reference to a specific commit (normally to the the last commit in a local repository).

Git Diff Unstaged

Shows the changes between the Working Directory and the Staging Area:

Git Diff Staged

Shows the changes between the Staging Area and the HEAD:

Create an alias git diffs, if you need to check these changed often:

Git Diff Staged and Unstaged

Shows all the changes between the Working Directory and the HEAD:

Create an alias git diffh, if you need to check these changed often:

Back to list

Forking projects to make your own changes lets you easily integrate your own contributions. But if you're not sending those changes back upstream—which means sending it back to the parent repository—you're at risk for losing track of them, which can cause divergent lines in your repository. To make sure all contributors are drawing from the same place, you'll need to know some principles of how git forking interacts with git upstream. In this blog, I'll introduce you to the basics, the gotchas, and even leave you with a cool tip to get you ahead of the curve.

Git upstream: Keep up-to-date and contribute

Let me start by detailing a common setup and the most basic workflow to interact with upstream repositories.

Graph

In a standard setup, you generally have an origin and an upstreamremote — the latter being the gatekeeper of the project or the source of truth to which you wish to contribute.

First, verify that you have already setup a remote for the upstream repository, and hopefully an origin too:

If you don't have an upstream you can easily add it with the remote command:

Verify that the remote is added correctly:

Now you can collect the latest changes of the upstream repository with fetch. Repeat this every time you want to get updates:

(If the project has tags that have not merged to master you should also do: git fetch upstream --tags)

Generally, you want to keep your local master branch as a close mirror of the upstreammaster and execute any work in feature branches, as they might later become pull requests.

At this point, it does not matter if you use merge or rebase, as the result will typically be the same. Let's use merge:

When you want to share some work with the upstream maintainers you branch off master, create a feature branch. When you're satisfied, push it to your remote repository.

You can also use rebase instead, then merge to make sure the upstream has a clean set of commits (ideally one) to evaluate:

If you need to squash a few commits into one you can use the awesome rebase interactive at this point.

Publish with git fork

After the above steps, publish your work in your remote fork with a simple push:

A slight problem arises if you have to update your remote branch feature-x after you've published it, because of some feedback from the upstream maintainers. You have a few options:

  • Create a new branch altogether with the updates from you and the upstream.
  • merge the updates from upstream in your local branch which will record a merge commit. This will clutter the upstream repository.
  • Rebase your local branch on top of the updates from upstream and do a force push onto your remote branch:

Personally I prefer to keep the history as clean as possible and go for option three, but different teams have different workflows. Note: You should do this only when working with your own fork. Rewriting history of shared repositories and branches is something you should NEVER do.

Tip of the day: Ahead/Behind numbers in the prompt

After a fetch, git status shows you how many commits you are ahead or behind of the synced remote branch. Wouldn't it be nice if you could see this information at your faithful command prompt? I thought so too so I started tapping with my bash chopsticks and cooked it up.

Here is how it will look on your prompt once you've configured it:

And this is what you'll need to add to your .bashrc or equivalent—just a single function:

You can enrich your bash prompt with this new function, ahead_behind, to have the desired effect. I leave the colorization as an exercise for the reader.

Sample prompt:

Inner workings

For those who like details and explanations here is how it works:

We get the symbolic name for the current HEAD, i.e. the current branch:

We get the remote that the current branch is pointing to:

Sourcetree Diff Against Current Not Working

We get the branch onto which this remote should be merged (with a cheap Unix trick to discard everything up to and including the last forward slash [ / ]):

Git Diff Against Current Sourcetree

Now we have what we need to collect the number of counts for the commits we are ahead or behind:

We use the age-old Unix tr to convert the TAB to a separator |.

Getting started with git upstream

That is a basic walk-through on git upstream — how to set up a git upstream, create a new branch, collect changes, publish with git fork, and a sweet tip for how many commits ahead/behind you are of your remote branch.

Sourcetree Diff Against Current Weather

Bitbucket Server includes fork synchronization which basically relieves the developer from all the burden of keeping up to date with its forks, and Bitbucket Cloud has an easy 1-step sync check it out!

Sourcetree Diff Against Current Graph

Follow me @durdn and the awesome @Bitbucket team for more DVCS rocking.





broken image