Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Less Fat Luke
May 23, 2003

Exciting Lemon
Or "git pull --rebase" in your branch. Definitely nicer than pushing something with a bunch of merge commits.

Adbot
ADBOT LOVES YOU

Snak
Oct 10, 2005

I myself will carry you to the Gates of Valhalla...
You will ride eternal,
shiny and chrome.
Grimey Drawer
Thanks.

I'll probably just use git pull --rebase, as it's simple but explicit. Since I'm helping classmates with less experience than me, I don't want to reconfigure pull's default behavior.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


I'm trying to think of instances where git pull --rebase would gently caress up or be the wrong answer, and I'm coming up empty. Unless you're in a group that wants every merge commit for 100% true to life history, and nuts to that.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Ciaphas posted:

I'm trying to think of instances where git pull --rebase would gently caress up or be the wrong answer, and I'm coming up empty. Unless you're in a group that wants every merge commit for 100% true to life history, and nuts to that.

Speaking as someone who has git pull setup to rebase by default, I have encountered the following situation:

Your upstream looks like oldest -> older -> old. Your checkout is up-to-date with upstream.

Your coworker has been doing some work and hasn't pulled in a few hours. Their checkout looks like oldest -> unpublished.

Your coworker asks you to pull directly from their checkout and take a look at what they're doing.

What you want your repo to look like, in the best possible world: oldest -> older -> old -> unpublished (rebasing their tree to the head of your tree).

What would be acceptable, if somewhat annoying: getting an error saying that you have to do some sort of manual merge, because you have very stupidly asked to do a rebasing pull from a checkout that is not your upstream.

What git pull --rebase actually does: oldest -> unpublished -> older -> old (rebasing your tree to the head of their tree).

In summary, git pull --rebase works perfectly as long as you remember that it always moves the commits that are in your tree to be at the end of where you're pulling from. If you're pulling "unpublished" commits which should be rebased, then you need to rebase in "the other direction" that what it does by default.

That said, this is not a common situation and it's super easy to avoid.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Yeah usually if I'm not 100% sure of what the history on all ends looks like I'll just fetch and either merge, rebase, or do nothing as required (headless checkout is fine if I'm just reviewing), so I haven't run into that edge case yet.

Vanadium
Jan 8, 2005

How do y'all feel about history-rewriting on published feature branches? I feel as long as it's obviously my personal feature branch it's cool to do whatever to the history even though it's technically public, but I guess it gets iffy when someone else shows up and wants to work on the same thing.

apseudonym
Feb 25, 2011

Vanadium posted:

How do y'all feel about history-rewriting on published feature branches? I feel as long as it's obviously my personal feature branch it's cool to do whatever to the history even though it's technically public, but I guess it gets iffy when someone else shows up and wants to work on the same thing.

Are other people using it? if so probably don't.

That said on my repos on github I require people rebase fixes for their pull request instead of adding more and more 'fix X' commits.

ExcessBLarg!
Sep 1, 2001

Thermopyle posted:

What's the best/fairest/easiest/most-standard way to handle this workflow?
It depends how much your changes actually conflict (on a line-by-line level) with theirs. If it's "a lot", then working off your own master you're going to be swimming upstream the whole time. If the changes are generally orthogonal there's two workflows depending on the amount of actual conflict:

1. They do a merge on your master before you make any changes. It should be a no-op merge since you should have no outstanding changes on it, but if there are they need to check if the merge has any material changes, and if it does, figure out if they need to incorporate them, otherwise they'll end up doing the equivalent of an "ours" merge. Either way, you're now on equal footing. Then you can make your changes on master and they can merge them in, since the changes are orthogonal there shouldn't be conflict.

2. You make a branch of their master and pretend to be "them" in option #1. So you're still doing work on "your" master and merging it into "theirs", handling any conflicts that come along the way, while periodically pulling from their real master. For delivery, you tell them to pull from your version of "their" master and since you've already resolved the conflicts, they should be clean merges.

For either approach to be worthwhile though there has to be value in maintaining your changes on an external branch. You probably already know this, but if was, for example, an open-source project where you're allowed by contract to maintain your changes in the open, then you can use those changes later on other projects while avoiding the IP issues (or general maintenance issues) around their version. If the changes you make can't be repurposed though, there may not be much value in maintaining them separately.

ExcessBLarg!
Sep 1, 2001

Snak posted:

When my local copy of master gets behind the remote, it seems like that's when it's better to rebase my local to the remote, rather than merge them. Does that seem correct?
If your work is being done on a feature branch, what are the changes to your master that aren't already reflected on the remote? If your local master is merely "old", then both "git merge" and "git rebase" will do a fast-forward with the remote's content. If it's not doing that, then there's something outstanding on your master that's getting regularly cleared out on the remote, and it's worth figuring out what that is to avoid headaches for others.

If you're referring to small changes you're making on master outside of a feature branch, then yes it's usually easier to rebase those against master than to merge. Nobody really likes "one commit + one merge commit" showing up in history all the time.

ExcessBLarg! fucked around with this message at 19:11 on Sep 3, 2016

ExcessBLarg!
Sep 1, 2001

Vanadium posted:

How do y'all feel about history-rewriting on published feature branches?
It's fine, and possibly preferred, so long as there's an agreement between you and the others working on the project that you're going to do that.

For branches that are truly private, I'll usually prefix the branch with my username so it's clear to others that I own it, and that I'll probably be regularly force-pushing to it.

Snak
Oct 10, 2005

I myself will carry you to the Gates of Valhalla...
You will ride eternal,
shiny and chrome.
Grimey Drawer
This is in a class where a lot of people are using git for the first time, so people are constantly pushing new or broken files to master. People creating files in the wrong directory and people pushing without checking that it still compiles after their changes.

So it's not a huge deal to clean this stuff up, but I would rather push my feature branch merge commit and then fix the mess on a seperate "cleaned up bad files" commit.

Does that make sense? I'm new at this too, I'm just a little more comfortable with how git works than some of my classmates, so I'm trying to be as helpful as possible.

apseudonym
Feb 25, 2011

Snak posted:

This is in a class where a lot of people are using git for the first time, so people are constantly pushing new or broken files to master. People creating files in the wrong directory and people pushing without checking that it still compiles after their changes.

So it's not a huge deal to clean this stuff up, but I would rather push my feature branch merge commit and then fix the mess on a seperate "cleaned up bad files" commit.

Does that make sense? I'm new at this too, I'm just a little more comfortable with how git works than some of my classmates, so I'm trying to be as helpful as possible.

You shouldn't have broken commits in the tree. There's probably not much you can do dealing with students but stuff shouldn't get merged to master if it doesn't loving work. You should strive to never have commits like "fix breakage" or "address reviewer comments"

Series DD Funding
Nov 25, 2014

by exmarx
Making a separate commit for cleaning up crap to differentiate it from your features is preferable, yes. But when you're at the level where classmates can't even be bothered to check if their code compiles, much less runs, git feng shui is pretty far down on the lot of priorities

Snak
Oct 10, 2005

I myself will carry you to the Gates of Valhalla...
You will ride eternal,
shiny and chrome.
Grimey Drawer

Series DD Funding posted:

Making a separate commit for cleaning up crap to differentiate it from your features is preferable, yes. But when you're at the level where classmates can't even be bothered to check if their code compiles, much less runs, git feng shui is pretty far down on the lot of priorities

Yeah, but I don't want to develop bad habits because they are convenient in school. I want to practice doing things the right way.

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

What is an easy way to deal with ancillary changes that happened to a file that I'm committing to keep the commits clean? (in git)

For example, I was working on a file that had a few lines with extra spaces at the end of the line. My editor cleaned those up automatically, but I'd like to not keep those changes in the feature commit. Is there a way to commit part of a file? I'd like to be able to make the ancillary changes another separate commit ("removed extraneous whitespace"). Last time, I just put the extra spaces back in to get around it quick, but that doesn't seem like the right way to do it.

I know one answer is "don't make unrelated changes at that time" but sometimes it just happens or it is a good time to make a little change or it will get lost in the todo list.

apseudonym
Feb 25, 2011

taqueso posted:

What is an easy way to deal with ancillary changes that happened to a file that I'm committing to keep the commits clean? (in git)

For example, I was working on a file that had a few lines with extra spaces at the end of the line. My editor cleaned those up automatically, but I'd like to not keep those changes in the feature commit. Is there a way to commit part of a file? I'd like to be able to make the ancillary changes another separate commit ("removed extraneous whitespace"). Last time, I just put the extra spaces back in to get around it quick, but that doesn't seem like the right way to do it.

I know one answer is "don't make unrelated changes at that time" but sometimes it just happens or it is a good time to make a little change or it will get lost in the todo list.

git add -p

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

Thank you

ExcessBLarg!
Sep 1, 2001

Snak posted:

Yeah, but I don't want to develop bad habits because they are convenient in school. I want to practice doing things the right way.
The problem you'll run into is that you're working with a group of people who aren't motivated to do things the right way, or at least don't have time to. Sure, separating the "fix the compile" commit from a set of feature commits is a good thing, relatively low cost, and something I'd do. Omnibus commits, the kind that your classmates are pushing, will probably not be helpful and unreviewable.

I wouldn't worry too much about getting git right on this. Do your work on a private branch (doesn't really need to be a feature branch), folding in their changes at convenient times, but don't worry too much about having a perfect history. I'm guessing it's not that long of project (beyond one semester) anyways. The only things you really need to be able to do is cursory review of others changes, and be able to revert to a known-working version when poo poo really breaks.

If you really want to learn git well, get involved in some established projects that exhibit good commit, merge, and review policies.

chippy
Aug 16, 2006

OK I DON'T GET IT

Snak posted:

Yeah, but I don't want to develop bad habits because they are convenient in school. I want to practice doing things the right way.

Just to say, don't expect things to necessarily be better in the real world. There's a dev in my team who doesn't seem to be able to get his head around source control, how to use it well, or why it's even a good idea. He often won't commit or push anything until he's prompted, and then you get a fortnight's work in a single commit with the message 'Update'. He mostly gets away with it because we do a lot of working on our own individual projects, it only tends to come to light in situations like the current one where he's in India, and I'm called upon to fix something he's worked on, find out that the remote hasn't been updated since god knows when and all the most recent changes are in uncommitted files in his working directory that I can't even commit and push because nobody knows his git password! That's once I've worked out which of the multiple versions of each project is even the right one, because he makes multiple stupidly named backup copies of everything because he doesn't use source control. He's a loving nightmare.

(and yes, I am considering a move before anyone suggests it)

chippy
Aug 16, 2006

OK I DON'T GET IT
Quick rebase question: I've got a fairly long running feature branch. A few commits back I merged it into my develop branch, but I continued working on it. If I were to now rebase it onto develop, would it just rebase the few commits that were made since the last time I merge it in, or everything from the point the branch was created?

o.m. 94
Nov 23, 2009

Rebase ignores merge commits by default, and just FYI you can use --preserve-merges to bypass this. I think the machinery for --preserve-merges is a bit involved though, it doesn't always include all merge commits to avoid redundancy or something, I dunno.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

chippy posted:

Quick rebase question: I've got a fairly long running feature branch. A few commits back I merged it into my develop branch, but I continued working on it. If I were to now rebase it onto develop, would it just rebase the few commits that were made since the last time I merge it in, or everything from the point the branch was created?

It will see that the older commits are already there in the branch you are rebasing on to, and not try to reapply them.

Pixelboy
Sep 13, 2005

Now, I know what you're thinking...
So -- philosophical git question. Imagine working in an environment that has extraordinary legal compliance or contractual obligations in regards to change management, auditing, etc. etc.

Wouldn't using a RCS that allows you to effectively rewrite history (rebase) be.... an extraordinarily bad idea?

apseudonym
Feb 25, 2011

Pixelboy posted:

So -- philosophical git question. Imagine working in an environment that has extraordinary legal compliance or contractual obligations in regards to change management, auditing, etc. etc.

Wouldn't using a RCS that allows you to effectively rewrite history (rebase) be.... an extraordinarily bad idea?

You can rewrite any version control system's history. Git is far more robust to losing old commits (even when rebasing) than things like svn. Git is far more robust against modification of the history too.


tl;dr: no.

apseudonym fucked around with this message at 02:05 on Sep 10, 2016

comedyblissoption
Mar 15, 2006

when people refer to rewriting history as useful they usually mean only the history of private commits or stories not merged to a main branch yet

rewriting public history is generally avoided

Less Fat Luke
May 23, 2003

Exciting Lemon
Also pretty much every Git service now supports blocking force pushes (rewrites) to protected branches such as master, so you can certainly ensure that history isn't changed.

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today
More relevantly, as apseudonym suggested, git does not actually support genuinely rewriting history at all, just moving branch pointers around, which is recorded in the reflog. Normally unreferenced commits (as arise from "rewritten" history) are garbage collected after a month or so, but you can just disable that if you have extraordinary demands.

smackfu
Jun 7, 2004

apseudonym posted:

You can rewrite any version control system's history.

As an end user?

22 Eargesplitten
Oct 10, 2010



On GitHub, for general viewing, do I want to let the files upload with the crlf line endings, and then just configure my Windows computer to automatically convert from crlf to lf using

code:
git config --global core.autocrlf true
?

That's what it sounds like from [url=https://help.github.com/articles/dealing-with-line-endings/[/url], but I want to make sure that's how it's generally done.

return0
Apr 11, 2007
I asked this question about git log on stack overflow: http://stackoverflow.com/questions/39946636/git-log-inconsistency-in-file-states

The problem is that the log for a file seems inconsistent; it looks like the file was deleted, but it is then edited and still exists. It looks from the log as though it went:

Add --> [bunch of edits] --> Delete --> [bunch of edits]

I've added a gist here to show the file I mean, the highlighted line is the delete. Is there something fundamental I'm missing about git log? The command I am running is:

code:
git log --format=format:"%H, %at, %aE, %aN, %ce, %cN" --name-status --full-history --diff-filter=ACDMRTUXB -- test/test_generated_site.rb

Gounads
Mar 13, 2013

Where am I?
How did I get here?
Is it possible the next commit is a merge and they chose to take their own modified version over the deleted version?

return0
Apr 11, 2007

Gounads posted:

Is it possible the next commit is a merge and they chose to take their own modified version over the deleted version?

It's probably this. I did this:

code:
git init . 
touch test_file
git add test_file && git commit -m "add test file"
git checkout -b a
git checkout -b b
git rm test_file && git commit -m "delete test file"
git checkout a
echo "edit" > test_file && git commit -am "edit test file"
git merge b
git checkout HEAD -- test_file 
git commit -m "complete merge"
...and was able to replicate the log:

code:
> git log --format=format:%H --name-status --diff-filter=ACDMRTUXB

92dfa538ba46b1e6fa40a385940b16d7d30729f5
M   test_file

728a129c18bca0173c3699743408ee3b0b7a8e6c
D   test_file

11f55702b525b3ba3b3886cd34e83c4e4b7a3737
A   test_file

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
git log --graph makes logs involves merges much more sensible.

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

I need to apply the inverse of a git stash, or something.

I edited a file, made change A. Then I stashed this change away. Then I went into my text editor, and made change B. At this point I thought change A was gone, but I think the editor had not reloaded from disk so that stashed change was still there. Now if I run a "git diff" i see changes A and B.

Is there something I can do to unapply that stash, so that if I run "git diff" it will only show me change B?

I was asking on IRC, and someone suggested I do "git show stash | git apply -R", but that results in "fatal: unrecognized input"

They think "the problem is that git stash saves the stash as a merge commit", so I have no idea what to do about that and they seem out of suggestions.

apseudonym
Feb 25, 2011

peepsalot posted:

I need to apply the inverse of a git stash, or something.

I edited a file, made change A. Then I stashed this change away. Then I went into my text editor, and made change B. At this point I thought change A was gone, but I think the editor had not reloaded from disk so that stashed change was still there. Now if I run a "git diff" i see changes A and B.

Is there something I can do to unapply that stash, so that if I run "git diff" it will only show me change B?

I was asking on IRC, and someone suggested I do "git show stash | git apply -R", but that results in "fatal: unrecognized input"

They think "the problem is that git stash saves the stash as a merge commit", so I have no idea what to do about that and they seem out of suggestions.

So A didn't actually get stashed? Use git stash -p and select only the parts of A.

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

apseudonym posted:

So A didn't actually get stashed? Use git stash -p and select only the parts of A.
"A" was put in a stash, but the editor apparently did not reload the file from disk or warn me because its a piece of poo poo (atom).

e: So now to isolate only "B" changes, I want to "apply" stash A, except in reverse. Does that make sense?

peepsalot fucked around with this message at 22:58 on Oct 16, 2016

Hughlander
May 11, 2005

peepsalot posted:

"A" was put in a stash, but the editor apparently did not reload the file from disk or warn me because its a piece of poo poo (atom).

e: So now to isolate only "B" changes, I want to "apply" stash A, except in reverse. Does that make sense?

Git add -p?

nielsm
Jun 1, 2009



peepsalot posted:

"A" was put in a stash, but the editor apparently did not reload the file from disk or warn me because its a piece of poo poo (atom).

e: So now to isolate only "B" changes, I want to "apply" stash A, except in reverse. Does that make sense?

Stash B.
Make a new temporary branch from your starting point. Apply A from the stash. Commit. Apply B from stash. Commit.
Check out starting point again. Cherry pick commit after applying B on the temp branch.

That should isolate those changes.

It's probably possible to do in a shorter way, but this seems like the most straight-forward.

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

I used Hughlander's suggestion and got back where I wanted to be, thanks.

Adbot
ADBOT LOVES YOU

The Fool
Oct 16, 2003


I'm having problems wrapping my head around git remote right now. I've never had issues using git with github, but this is a little different.

I have a collection of scripts that do various admin things, that I want to be available to my co-workers. As I add and edit new scripts I don't want to have to worry if the version on the shared folder is up to date, and I'd like to be able to do version tracking on my local copies of the scripts.

My thought was to have a local repository that I do edits on, then have a remote repository that I can push changes to, that would live on the network share for people to access. They would not be using git at all, just running different scripts as needed.

What would be the best way to set this up?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply