Posts

Showing posts with the label Git

Count Number Of Lines In A Git Repository

Answer : xargs will do what you want: git ls-files | xargs cat | wc -l But with more information and probably better, you can do: git ls-files | xargs wc -l git diff --stat 4b825dc642cb6eb9a060e54bf8d69288fbee4904 This shows the differences from the empty tree to your current working tree. Which happens to count all lines in your current working tree. To get the numbers in your current working tree, do this: git diff --shortstat `git hash-object -t tree /dev/null` It will give you a string like 1770 files changed, 166776 insertions(+) . If you want this count because you want to get an idea of the project’s scope, you may prefer the output of CLOC (“Count Lines of Code”), which gives you a breakdown of significant and insignificant lines of code by language. cloc $(git ls-files) (This line is equivalent to git ls-files | xargs cloc . It uses sh ’s $() command substitution feature.) Sample output: 20 text files. 20 unique files. 6 fi...

Can't Clone Private Repo On Github From SourceTree

Image
Answer : It happens because SourceTree didn't get some private access from Github while authenticating. So the solution is very simple Login into your Github account on any browser From top right corner select SETTINGS Now select DEVELOPER SETTINGS From DEVELOPER SETTINGS select PERSONAL ACCESS TOKEN Now from PERSONAL ACCESS TOKEN select GENERATE TOKEN Fill Note as sourcetree and Check All Scopes from checkbox as show in below screenshots After Click on Generate Token Now Open sourceTree Click on sourceTree preference & Click add Account Select options as shown in below screen shot Enter username as your Github account username and password as Generated Token from Github Click on SAVE now you might see all your repository are visible and can clone too Hope it helps I had same problem. My fix way: Remove user from SourceTree settings (optional, i not sure); Add you account in setting and generate new SSH key (it's a main part of fix); ...

Cannot Ignore .idea/workspace.xml - Keeps Popping Up

Answer : I was facing the same issue, and it drove me up the wall. The issue ended up to be that the .idea folder was ALREADY commited into the repo previously, and so they were being tracked by git regardless of whether you ignored them or not. I would recommend the following, after closing RubyMine/IntelliJ or whatever IDE you are using: mv .idea ../.idea_backup rm .idea # in case you forgot to close your IDE git rm -r .idea git commit -m "Remove .idea from repo" mv ../.idea_backup .idea After than make sure to ignore .idea in your .gitignore Although it is sufficient to ignore it in the repository's .gitignore, I would suggest that you ignore your IDE's dotfiles globally. Otherwise you will have to add it to every .gitgnore for every project you work on. Also, if you collaborate with other people, then its best practice not to pollute the project's .gitignore with private configuation that are not specific to the source-code of the project. I had t...

Adding Git Credentials On Windows

Answer : Ideally, you should enter: git config --global credential.helper manager-core Then your password would be stored in the Windows Credential Manager. See more at "Unable to change git account". On the first push, a popup will appear asking for your credentials (username/password) for the target server (for instance github.com ) If not, that might means your credentials were already stored. If they are incorrect, a simple git credential-manager reject https://github.com will remove them (on Windows, again. On Mac: git credential-osxkeychain erase https://github.com ) With Git 2.29 (Q4 2020), the parser in the receiving end of the credential protocol is loosen to allow credential helper to terminate lines with CRLF line ending, as well as LF line ending. See commit 356c473 (03 Oct 2020) by Nikita Leonov ( nyckyta ). (Merged by Junio C Hamano -- gitster -- in commit 542b3c2, 05 Oct 2020) credential : treat CR/LF as line endings in the credential protocol...

Cannot Login To SourceTree

Answer : Try quitting the SourceTree app and re-launching. I had a similar problem. My id.atlassian.com credentials worked online but repeatedly failed in SourceTree. It worked for me after a relaunch. Atlassian recommends sticking with the older version at the moment: https://twitter.com/sourcetree/status/699624992003244033 Update On Feb 22, Atlassian apologized and released SourceTree 2.2.2. However, some folks are still tweeting issues with the initial login on the release announcement.

Create Pull Request Button Is Disabled

Answer : In my case, the pull request Title field didn't auto-populate like it usually does. Once I typed in a title, the button became active. From Github Developer Support: Also, I know this might seem strange, but could you try selecting the base repo/branch from the drop down list (even if this already seems selected), and give this another go. It could that, for whatever reason, the pull request creation flow isn't picking this up implicitly. I have also logged out and logged in again. After that, everything was fine!

All GIT Patches I Create Throw Fatal: Unrecognized Input

Answer : There is format problem in patch file. To fixthe path file: Open your patch file in notepad++ then enter these two menus: Encoding/Convert to UTF-8 Edit/EOL conversion/Unix (LF) Run: git apply --reject --whitespace=fix your_patch.patch Updated You might have a file which was not encoded to UTF-8. To fix that on *nix systems (MacOS, Linux etc.) iconv -f ascii -t utf-8 fix.patch -o fix_utf8.patch For windows you can try: Get-Content .\fix.patch | Set-Content -Encoding utf8 fix_utf8.patch If your file may already have color codes in it you can try: git apply --reject --whitespace myfile.patch Passing in color param seems to fix the problem. git diff HEAD --color=never > fix.patch And now check returns no error message. git apply fix.patch --check Changing my .gitconfig file from [color] ui = always change to always [color] ui = auto Fixed my problem so I do not have to pass color option when diffing to patch file. UPDATE: ...

Create Git Branch With Current Changes

Answer : If you hadn't made any commit yet, only (1: branch) and (3: checkout) would be enough. Or, in one command: git checkout -b newBranch As mentioned in the git reset man page: $ git branch topic/wip # (1) $ git reset --hard HEAD~3 # (2) NOTE: use $git reset --soft HEAD~3 (explanation below) $ git checkout topic/wip # (3) You have made some commits, but realize they were premature to be in the " master " branch. You want to continue polishing them in a topic branch, so create " topic/wip " branch off of the current HEAD . Rewind the master branch to get rid of those three commits. Switch to " topic/wip " branch and keep working. Note: due to the "destructive" effect of a git reset --hard command (it does resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded), I would rather go with: $ git reset --soft HEAD~3 # (2) This would make sure I'm not losing any ...

Control Freak: Commit Rejected. Foxtrot Merges Not Allowed In Bitbucket

Image
Answer : That is related to Foxtrot merges, specifcally prohibited on BitBucket: A foxtrot merge is a specific sequence of git commits. A particularly nefarious sequence. Out in the open, in lush open grasslands, the sequence looks like this: But foxtrots are rarely seen in the open. They hide up in the canopy, in-between the branches. I call them foxtrots because, when caught mid-pounce, they look like the foot sequence for the eponymous ballroom dance: Foxtrot merges are bad because they change origin/master’s first-parent history. The parents of a merge commit are ordered. The first parent is HEAD. The second parent is the commit you reference with the git merge command. You can think of it like this: git checkout 1st-parent git merge 2nd-parent If pushed: As explained in "GIT: How can I prevent foxtrot merges in my 'master' branch?", commit ' D ' is a foxtrot merge because ' origin/master ' is its 2nd parent. This is the result of a pull (fetch ...

Can't Push Refs To Remote Try Running Pull First To Integrate Your Changes

Answer : You get this try running pull first to integrate your changes whenever your local branch and your remote branch are not on the same point, before your changes. remote branch commits : A -> B -> C -> D local branch commits : A -> B -> C -> Local_Commits Now clearly, there's a change D that you don't have integrated locally. So you need to rebase , then push, which will lead to the following. remote branch commits : A -> B -> C -> D local branch commits : A -> B -> C -> D -> Local_Commits To solve your issue, do the following git pull --rebase origin branchname git push origin branchname I was getting this message in my Azure DevOps Repos environment because the server had a branch policy on the master branch that requires pull request approval and I was trying to push to master directly. Even after pull and rebase the same message appears. I don't think VS Code really knows how to interpret this specific err...

Create A Tag In A GitHub Repository

Image
Answer : You can create tags for GitHub by either using: the Git command line, or GitHub's web interface. Creating tags from the command line To create a tag on your current branch, run this: git tag <tagname> If you want to include a description with your tag, add -a to create an annotated tag: git tag <tagname> -a This will create a local tag with the current state of the branch you are on. When pushing to your remote repo, tags are NOT included by default. You will need to explicitly say that you want to push your tags to your remote repo: git push origin --tags From the official Linux Kernel Git documentation for git push : --tags All refs under refs/tags are pushed, in addition to refspecs explicitly listed on the command line. Or if you just want to push a single tag: git push origin <tag> See also my answer to How do you push a tag to a remote repository using Git? for more details about that syntax above. Creating tags through GitHub's web int...

Can I Restore Deleted Files (undo A `git Clean -fdx`)?

Answer : No. Those files are gone. (Just checked on Linux: git clean calls unlink() , and does not backup up anything beforehand.) git clean -fdxn Will do a dry run, and show you what files would be deleted if you ran git clean -fdx (of course this is only helpful if you know this ahead of time, but for next time) IntelliJ/Android Studio allows restoring files from local history.

Cannot Find FileMerge (opendiff Tool) But I Have Xcode 4.6 Installed

Answer : FileMerge is located at within Xcode. From the command-line: cd /Applications/Xcode.app/Contents/Applications/ open . Go into that directory once it opens: Right-click on the app Choose "Make alias" Move that alias to your Applications directory You're all set. Strange. "XCode 4.5, where is FileMerge ?" suggests: The FileMerge that is bundled with Xcode 4.5 doesn't work as a standalone application. I tried compressing it from the application bundle. I was able to expand it to show the FileMerge app on the desktop. But when I tried to run it I got an error saying it couldn't be opened. Apple's developer downloads site has every version of Xcode. You could try trashing your current version of Xcode 4.5, downloading Xcode 4.5 from the developer downloads site, and see if FileMerge is there. If not, you can download Xcode 4.4 and see if that has FileMerge. Indeed, I downloaded a fresh new install o...

Create A Git Patch From The Uncommitted Changes In The Current Working Directory

Answer : If you haven't yet commited the changes, then: git diff > mypatch.patch But sometimes it happens that part of the stuff you're doing are new files that are untracked and won't be in your git diff output. So, one way to do a patch is to stage everything for a new commit ( git add each file, or just git add . ) but don't do the commit, and then: git diff --cached > mypatch.patch Add the 'binary' option if you want to add binary files to the patch (e.g. mp3 files): git diff --cached --binary > mypatch.patch You can later apply the patch: git apply mypatch.patch git diff for unstaged changes. git diff --cached for staged changes. git diff HEAD for both staged and unstaged changes. git diff and git apply will work for text files, but won't work for binary files. You can easily create a full binary patch, but you will have to create a temporary commit. Once you've made your temporary commit(s), you can create the patch with: git fo...

Can I Delete A Git Commit But Keep The Changes?

Answer : It's as simple as this: git reset HEAD^ Note: some shells treat ^ as a special character (for example some Windows shells or ZSH with globbing enabled), so you may have to quote "HEAD^" in those cases. git reset without a --hard or --soft moves your HEAD to point to the specified commit, without changing any files. HEAD^ refers to the (first) parent commit of your current commit, which in your case is the commit before the temporary one. Note that another option is to carry on as normal, and then at the next commit point instead run: git commit --amend [-m … etc] which will instead edit the most recent commit, having the same effect as above. Note that this (as with nearly every git answer) can cause problems if you've already pushed the bad commit to a place where someone else may have pulled it from. Try to avoid that There are two ways of handling this. Which is easier depends on your situation Reset If the commit you want to ...