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
ToxicFrog
Apr 26, 2008


The Fool posted:

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?

The tricky thing here is that if it's a bare repository, they can't run scripts directly from it, and if it's a non-bare repository, you can't push to it.

Offhand, I can think of three different ways to do this:
- Don't bother with a remote at all. When you want to push a new version, run git --work-tree=/path/to/network/share reset --hard HEAD
- Clone your working repo onto the network share (as a non-bare repo) and then pull from there to update: (cd /path/to/network/share && git pull)
- Create a bare repo as a remote (not necessarily on the network share) and install a hook that causes it to checkout its contents to the share when you git push to it

Of these, I'd probably just go with #1, given the assumption that your coworkers aren't using git in the first place.

Adbot
ADBOT LOVES YOU

The Fool
Oct 16, 2003


ToxicFrog posted:

The tricky thing here is that if it's a bare repository, they can't run scripts directly from it, and if it's a non-bare repository, you can't push to it.

Offhand, I can think of three different ways to do this:
- Don't bother with a remote at all. When you want to push a new version, run git --work-tree=/path/to/network/share reset --hard HEAD
- Clone your working repo onto the network share (as a non-bare repo) and then pull from there to update: (cd /path/to/network/share && git pull)
- Create a bare repo as a remote (not necessarily on the network share) and install a hook that causes it to checkout its contents to the share when you git push to it

Of these, I'd probably just go with #1, given the assumption that your coworkers aren't using git in the first place.

Yeah, most of what I was reading assumes wanting to use the network share as the main repository for multiple git users, and that used a bare repository, and that's just not what I want.

Thanks for the info, #1 sounds like it's going to be the best bet.

e: it works perfectly

The Fool fucked around with this message at 01:36 on Oct 18, 2016

Kobayashi
Aug 13, 2004

by Nyc_Tattoo
Is `git mv` the best way to rename a file and retain its history such that `git log follow` works? I know Linus has some weird thing about renames not being something Git cares about it, but this is a repo that I have control over, so I'm trying to find the "safest" way to rename files and retain history.

wolffenstein
Aug 2, 2002
 
Pork Pro
Yes.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Whenever possible, I also try to not change and move a file in the same commit.

HFX
Nov 29, 2004
Does anyone here use GitLab?

I've been playing with the merge options and don't like that it creates a merge even when I've rebased on to the head of the branch I'm merging. I would like it to behave more git does locally where it will FF if possible and only do a merge otherwise. Is there something in the settings I can set to allow for the desired behavior?

necrotic
Aug 2, 2005
I owe my brother big time for this!
It's apparently an Enterprise feature.

https://docs.gitlab.com/ee/user/project/merge_requests/fast_forward_merge.html

tak
Jan 31, 2003

lol demowned
Grimey Drawer

Kobayashi posted:

Is `git mv` the best way to rename a file and retain its history such that `git log follow` works? I know Linus has some weird thing about renames not being something Git cares about it, but this is a repo that I have control over, so I'm trying to find the "safest" way to rename files and retain history.

`git mv old new` is just shorthand for `mv old new && git add old new`. `git log --follow` determines renames based solely on % similarity, which iirc defaults to 80%.

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

I have a build process that involves cloning a repo "project1", and then copying files from another repo "project2" to a dir inside of that project1, and running a bunch of build scripts, generating .o files etc all over the place and eventually i get a tar file with the full project build in it.

project1 is huge, and cloning it takes a long time, so in the master script that starts all this, instead of wiping the whole build dir and cloning a fresh one, can I do something like "git checkout -f " and that would have the same result?

chippy
Aug 16, 2006

OK I DON'T GET IT

peepsalot posted:

I have a build process that involves cloning a repo "project1", and then copying files from another repo "project2" to a dir inside of that project1, and running a bunch of build scripts, generating .o files etc all over the place and eventually i get a tar file with the full project build in it.

project1 is huge, and cloning it takes a long time, so in the master script that starts all this, instead of wiping the whole build dir and cloning a fresh one, can I do something like "git checkout -f " and that would have the same result?

Unless I'm misunderstanding, you can just do 'git pull' to pull down the latest changes to project1, instead of cloning the whole thing afresh.

ExcessBLarg!
Sep 1, 2001

peepsalot posted:

project1 is huge, and cloning it takes a long time, so in the master script that starts all this, instead of wiping the whole build dir and cloning a fresh one, can I do something like "git checkout -f " and that would have the same result?
"git reset --hard" reverts any changes to tracked files. "git clean -dxf" deletes any untracked files and directories, including those mentioned in .gitignore. Running them together will revert the repo as if it were a fresh clone.

KoRMaK
Jul 31, 2012



Is there anyway to pluck a file that exists on another branch with it's commit history?

I have a feature branch that I want to pluck a file from and move into master, AND I want it's commit history. How could I do that?

nielsm
Jun 1, 2009



In Git?

I don't know how you'd actually perform it, but you'd have to generate a new branch mirroring the branch the file with changes comes from, but containing only that file. Then you can merge that new "fake" branch in.
I think "filter-branch" may be the command?

This would obviously still decouple those changes from the original branch, and you may get trouble if you later attempt to merge in that branch too.

ExcessBLarg!
Sep 1, 2001

KoRMaK posted:

Is there anyway to pluck a file that exists on another branch with it's commit history?
You can merge the two branches such that the merge commit only includes one file from the "other" branch. But both branch histories would show in "git log", the history wouldn't be specific to that one file.

nielsm
Jun 1, 2009



ExcessBLarg! posted:

You can merge the two branches such that the merge commit only includes one file from the "other" branch. But both branch histories would show in "git log", the history wouldn't be specific to that one file.

That was also my first idea, but not only will it cause history to show commits not relevant to the single file, it will probably also cause even bigger issues if you need to merge the branch in full later on.

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

nielsm posted:

In Git?

I don't know how you'd actually perform it, but you'd have to generate a new branch mirroring the branch the file with changes comes from, but containing only that file. Then you can merge that new "fake" branch in.
I think "filter-branch" may be the command?

This would obviously still decouple those changes from the original branch, and you may get trouble if you later attempt to merge in that branch too.
I've always done this with filter-branch, yeah. Never tried to merge in a superset of it again later though.

ExcessBLarg!
Sep 1, 2001

nielsm posted:

That was also my first idea, but not only will it cause history to show commits not relevant to the single file, it will probably also cause even bigger issues if you need to merge the branch in full later on.
That's probably true, but it's asking for trouble anyways. There's ways to deal with it down the road, but they result in "bigger issues if you need to merge another branch even later."

The problem with the filter-branch approach is that, if you do a full merge later you end up with two histories. You end up with an entire fake commit history related to the filter-branch procure, and then the real commit history from the merge. Both sets of commits would appear in the log and confuse the poo poo out of everybody.

If I was cherry-picking a file from a feature branch and wanted to "preserve" its history, I'd first tag the feature branch, then do a "git checkout feature_branch file" and commit it with a squashed log and a reference to the tag. That way the actual history of the file is preserved as a tag and I can see what's up from the log, but there's no branch merge operation actually done and no confusing quasi-real history.

Killer Low Life
Sep 6, 2010

Can anyone recommend a good out-of-the-box SVN hosting service with good bandwidth between US/Asia? Uptime and security are big factors too. Thanks in advance.

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!
Using git, I merged a couple of single commits from one branch to another. git log and Fisheye (and anything else I've tried) show only the expected commits, with the expected files changed. However, either one of the commits changed a bunch of other files, and they aren't listed anywhere as being changed, or there's some sort of hidden commit that happened and changed those files. The biggest problem is that I don't even know specifically which files have been changed. git diff between commits don't show the change, but I can see that the file contents changed mysteriously between two of adjacent commits in the history. What could possibly cause this, and how should I fix it? Should I just revert the whole branch to a time before any of those commits and patch in the diffs or something?

edit: Apparently the whole branch history somehow got merged in instead of a single commit. This causes a ton of extra commits to appear in the history, but they're all backdated, with no obvious way to separate out the unwanted ones. Is there a way to find out when some particular commits/merges were pushed to a specific branch, rather than when they were originally committed/pushed to their original branch?

Kilson fucked around with this message at 21:53 on Jan 17, 2017

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
If you only wanted single commits you should have cherry picked the commits specifically. Reset your branch to before the merge and try again.

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

Blinkz0rz posted:

If you only wanted single commits you should have cherry picked the commits specifically. Reset your branch to before the merge and try again.

I realize now that cherry pick was what I wanted. I'm still a little baffled as to how this happened, because there wasn't really any indication that it was happening. Diff showed only the 12 expected files had changed.

How can I reset to before the merge, when there's a bunch of stuff in the history from way before that? (Also, this merge got pushed to origin.) There doesn't appear to be a normal merge commit for this one, for some reason. At least it isn't displaying the way they usually do.

Or is reset based on topology, not ancestry, and resetting/rewinding before that would remove everything merged in, even if it appears months old?

Sorry, I'm pretty new to using git (from a long time using svn), so I don't quite understand how it works yet.

Vanadium
Jan 8, 2005

git reset moves the branch pointer to the given commit, so the new contents of the branch is all the commits reachable from that commit, dates don't really play into it. I'm not sure what you mean by topology vs ancestry, I thought ancestry defines the topology.

But if you're already published the current state of the branch, it's really bad form to try to rewrite history. You'd want to use git revert to undo specific commits/merges by introducing more commits. I think that might become super messy.

I'm not sure if git blame would be helpful to find out when certain changes appeared in your branch, I assume it will point to the original commits and not the merge commits, but I don't know from the top of my head.

It's not always obvious from glancing at git log what commits are reachable from the branch head, showing the history so linearly is kinda misleading when there's merges involved. I dunno what fisheye is exactly, have you used tools that visualize the history as a graph, so you can just trace all the lines and see where they go?

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

Vanadium posted:

git reset moves the branch pointer to the given commit, so the new contents of the branch is all the commits reachable from that commit, dates don't really play into it. I'm not sure what you mean by topology vs ancestry, I thought ancestry defines the topology.

I'm sure I was using incorrect terms. By ancestry I meant age, but what I said probably didn't make sense anyway.

quote:

But if you're already published the current state of the branch, it's really bad form to try to rewrite history. You'd want to use git revert to undo specific commits/merges by introducing more commits. I think that might become super messy.

Merging in all those changes (which I wanted to remove) already rewrote the history with all kinds of added junk. I wanted to get rid of it all.

quote:

I'm not sure if git blame would be helpful to find out when certain changes appeared in your branch, I assume it will point to the original commits and not the merge commits, but I don't know from the top of my head.

The problem was that there didn't seem to be a clear way of even determining what had been merged in, because most of it was dated far in the past.
Nobody had a recent version of that branch, because I'd been the only one working on it (doing hotfixes) for probably a couple months, so there wasn't anyone who could just do a diff or something.

I tried reverting to the commit before the bad merge, but at least some of the stuff that was dated before that was still in there, and it was going to be way too much work to go through everything and figure out what didn't belong.

quote:

It's not always obvious from glancing at git log what commits are reachable from the branch head, showing the history so linearly is kinda misleading when there's merges involved. I dunno what fisheye is exactly, have you used tools that visualize the history as a graph, so you can just trace all the lines and see where they go?

Fisheye is just some visualization tool that you can see history/logs (in text and graph form), you can browse the code and show differences between any commits, etc. The history graph just looked like a giant ball of yarn. I couldn't make any sense out of it.

In the end, I just force pushed the branch based on a backup we had from the friday before the bad merge to rewrite everything back to its correct state, then correctly cherry picked the necessary commits into the branch.

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
For future reference, you can always look through "git reflog" to find a previous state of a branch, no matter how mangled your history has gotten.

ToxicFrog
Apr 26, 2008


Also, if you're just using "git log", consider using "git log --oneline --graph --decorate" or even a graphical tool like "gitk" to get a better sense of history. You may have a better idea of what the results of the merge actually are once you've done so.

smackfu
Jun 7, 2004

What kind of git hooks do people find useful?

We have two pre commit hooks: one to prevent committing focused jasmine JavaScript tests (focused means it will only run that test when you run the entire suite) and one to prevent someone checking in our database scheme name (because it differs between environments and should come from a setting.)

smackfu fucked around with this message at 14:08 on Jan 31, 2017

ExcessBLarg!
Sep 1, 2001

Kilson posted:

Merging in all those changes (which I wanted to remove) already rewrote the history with all kinds of added junk.
Merging doesn't rewrite history. All it does is add a merge commit with two (or more) merge parents, which you can see in the "Merge:" line of "git log". Now, the default presentation of "git log" shows the commits from all merged branches mixed together and ordered by CommitDate, but if you do "git log --graph" you'll see the branch histories separated out.

Also, since merging is additive, and doesn't rewrite anything, you can always undo a merge with a 'git reset --hard MERGE_PARENT" where MERGE_PARENT is one of the parents listed in the "Merge:" line of the merge commit. If you've just done a merge, usually "git reset --hard HEAD^" does what you want.

Kilson posted:

Nobody had a recent version of that branch, because I'd been the only one working on it (doing hotfixes) for probably a couple months, so there wasn't anyone who could just do a diff or something.
You can always do a "git diff" between branch heads to see what the differences are, which is an approximation of what a merge would look like, except the merge does conflict resolution.

Kilson posted:

I tried reverting to the commit before the bad merge, but at least some of the stuff that was dated before that was still in there, and it was going to be way too much work to go through everything and figure out what didn't belong.
What did you do here?

Kilson posted:

In the end, I just force pushed the branch based on a backup we had from the friday before the bad merge to rewrite everything back to its correct state, then correctly cherry picked the necessary commits into the branch.
My advice would be to pay attention to commit IDs. Yes they're horrible SHA-1s, but the next time before doing a questionable merge, write down the commit at the top of "git log" for both branches and, when you're finished, pay attention what happened to them. If you ever need to reset, you'll know which commit IDs to use. You'll probably would've found that the "restore from backup, force push" commit ID was in your history the whole time an you could have reset to it instead.

KoRMaK
Jul 31, 2012



nielsm posted:

In Git?

I don't know how you'd actually perform it, but you'd have to generate a new branch mirroring the branch the file with changes comes from, but containing only that file. Then you can merge that new "fake" branch in.
I think "filter-branch" may be the command?

This would obviously still decouple those changes from the original branch, and you may get trouble if you later attempt to merge in that branch too.
Yep in git.

Ralith posted:

I've always done this with filter-branch, yeah. Never tried to merge in a superset of it again later though.


Ugh, both of these solutions seem like they would be more of a pain in the rear end down the road, so I just copy/pasted that poo poo into the branch. Thanks for the advice though!

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


In git is there a canonical way to update a commit message if it's already been pushed? My tactic so far has been to tsk at the the individual responsible (when it's not me :v:) then tell them to revert the commit, revert the revert (using the commit message they actually wanted), then push those results.

(We're required to put work order numbers in the summary, and I haven't gotten a trigger to check for that fully working yet.)

Ciaphas fucked around with this message at 23:42 on Feb 14, 2017

Edison was a dick
Apr 3, 2010

direct current :roboluv: only
Force push the history of you don't care about fast forwards, or use git replace to amend the message and tell people to reconfigure their clients to push and pull replace refs.

Alternatively have pre-merge commit review.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I always struggle with how to commit inconsequential changes. For example, I'll be working on a feature and come across some unused imports, some comments that need fixing, some formatting issues...any of which are unrelated to the feature I'm working on.

Lump those changes into a commit dealing with the actual feature I'm working on? Add additional commits for those changes to the feature branch I'm working on? Something else?

Data Graham
Dec 28, 2009

📈📊🍪😋



Making them their own commit doesn't cost anything, does it?

My principle is to always make every commit be about ONE thing, so you can find it later. What reason is there to hide inconsequential things under another thing? Why not just have a commit for them and label it as being inconsequential?

Monkey Fury
Jul 10, 2001

Thermopyle posted:

I always struggle with how to commit inconsequential changes. For example, I'll be working on a feature and come across some unused imports, some comments that need fixing, some formatting issues...any of which are unrelated to the feature I'm working on.

Lump those changes into a commit dealing with the actual feature I'm working on? Add additional commits for those changes to the feature branch I'm working on? Something else?

I am a literal monster but I have no real problems with with having a... more extensive commit history, as long as it explains what is being done and isn't a stream of "made an update" and other low-quality garbage.

Maybe doing clean-up in a block, writing individual commits, and squashing when you've finished that "block" is the answer?

Sedro
Dec 31, 2008

Thermopyle posted:

I always struggle with how to commit inconsequential changes. For example, I'll be working on a feature and come across some unused imports, some comments that need fixing, some formatting issues...any of which are unrelated to the feature I'm working on.

Lump those changes into a commit dealing with the actual feature I'm working on? Add additional commits for those changes to the feature branch I'm working on? Something else?

I like separate commits for unrelated changes, otherwise it's harder to review the feature. But I also like to make the small change when I see it, otherwise I'll forget.

What I do is make the unrelated change immediately and commit it. Then, once I'm in a good spot, interactive rebase to move the commit so it's the parent of the feature branch.

before:
pre:
o <- feature branch
o
o <- unrelated change
o
o
o <- master
after:
pre:
o <- feature branch
o
o
o
o <- unrelated change
o <- master
Then you can push the unrelated change to master if you want, and resume work on the feature branch.

Dirty Frank
Jul 8, 2004

Thermopyle posted:

I always struggle with how to commit inconsequential changes. For example, I'll be working on a feature and come across some unused imports, some comments that need fixing, some formatting issues...any of which are unrelated to the feature I'm working on.

Lump those changes into a commit dealing with the actual feature I'm working on? Add additional commits for those changes to the feature branch I'm working on? Something else?

I lump them in unless
a) its a change which will confuse the hell out of future diffs, like formatting xml with a tool cos its got out of control. If someone suspects a bug with my actual change I know that would make it v.difficult, so I separate the check-ins, and do a special "reformatting only, no functional changes" check in.
b) it costs me nothing to check in separately, like its an unrelated file with no other changes.

Its not ideal, I should be doing them all separately so the diffs are easy to navigate, but, gently caress.

Apparently separate is hard for me to spell, I love spell check.

ExcessBLarg!
Sep 1, 2001

Thermopyle posted:

I always struggle with how to commit inconsequential changes.
Of the few rules of thumb that dictate what to include in a commit, I try not to include anything in a feature commit that I wouldn't want to revert later, should I need to revert the commit. Usually if you're working on some feature, an unrelated-but-inconsequential change is something you wouldn't want to revert. Still, if the change is "close" to the code I'm modifying, such as whitespace consistency on an adjacent line I might lump it together anyways. But if the change is distant, such that it would generate its own diff chunk, I'll keep it separate. The behavior of "git add -p" dictates this somewhat too.

If I generate multiple "inconsequential" commits while working on a private branch I'll usually squash them together. I figure that they're noise in the history and people who might be reviewing the branch history really don't care about them.

I always keep a reformat run in a separate commit, because the deltas can be huge and they're functionally inconsequential by definition.

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

Thermopyle posted:

I always struggle with how to commit inconsequential changes. For example, I'll be working on a feature and come across some unused imports, some comments that need fixing, some formatting issues...any of which are unrelated to the feature I'm working on.

Lump those changes into a commit dealing with the actual feature I'm working on? Add additional commits for those changes to the feature branch I'm working on? Something else?
That's a process problem; the VC problem is just fallout. I'd say don't even make the side changes until you have some specific feature progress that you can commit. The examples you give don't sound like they're worth losing focus. Make a scratch note if something is wrong, not just sub-optimal.

Definitely keep functional changes separate from broad code restyling. That's a PITA to review together.

EmmyOk
Aug 11, 2013

I'm graduating soon so I decided to start putting all my personal projects and things on GitHub so I can show them off to employers etc. The last few days whenever I commit anything be it edits to existing files or brand new files my GitHub website profile only lists me as having one contribution that day. I make multiple changes or add new programs and push them separately throughout the day and it still lists it as one contribution for the day. I'm the only person who contributes to my GitHub and every repository only has one branch. All the changes are made and new files added if I go and check the repos.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



boo_radley posted:

You avoid this kind of janitor work with a workspace-per-branch scheme. We have 900+ projects with multiple branches per project, so we'd feel a lot more pain immediately if we tried to pull in an entire project's code across all branches at once.

Huh. Let's say I have an e-commerce site that's three solutions: front-end, back-end services and internal management tooling. They share a project containing communications APIs/DTOs and whatnot. Let's say we want code to flow from a Dev to a QA into a Live branch. What is TFS supposed to look like if the admin doesn't begin with the assumption that it's supposed to work just like SVN?

Adbot
ADBOT LOVES YOU

tak
Jan 31, 2003

lol demowned
Grimey Drawer

EmmyOk posted:

The last few days whenever I commit anything be it edits to existing files or brand new files my GitHub website profile only lists me as having one contribution that day.

Are the repos all public?

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