1

I have the following branches:

master, css-merge-2016, php-merge-2016 and b4-selector-removal I was working on my local files and was committing to branch css-merge-2016 without any issue. But a couple of days back I had to checkout to a specific commit by starting the new branch b4-selector-removal.

After doing the above I switched to master branch, did a git pull. Now whenever I am checking out to the php-merge-2016 using git checkout php-merge-2016, git status -u shows me a list of files as untracked although I committed them from branch css-merge-2016.

And if I want to checkout to css-merge-2016 from php-merge-2016 a long list of files with the following statement:

The following untracked working tree files would be overwritten by checkout. Please move or remove them before you can switch branches. Aborting

If I do git checkout -f php-merge-2016 it lets me switch to that branch but again if I run git status -u all those red lines come up and said to be untracked.

css-merge-2016 and php-merge-2016 are meant for different purposes as their names suggest. And all the untracked files listed were created/worked on when I was working and committing to css-merge-2016 branch.

So if I use git add for those untracked files while on php-merge-2016 that may not hamper anything but if I do not add them can this cause any problem as far as git is concerned? On the other hand if I go ahead and git add those untracked files while on php-merge-2016 is this a good practice not to commit them. The problem is I will start working and commit to this branch. So if I add them won't git ask me to commit those files?

I am sorry if my question is not very clear. Please let me know if I should add more information.

I am worried of losing my works. How can I get rid of this situation keeping everything intact? Please help!

UPDATE:

These are the steps:

git checkout -b b4-selector-removal f990b78
to checkout into a new branch from specific revision (of css-merge-2016 branch)

git reset --hard

Output: HEAD is now at bf25410 Merge branch 'master' of https://github.com/abcd/site.main.drupal

git checkout master

Switched to branch 'master' Your branch is ahead of 'origin/master' by 4 commits.
(use "git push" to publish your local commits)
subrara@subrara-desktop:/var/www/devsite.com/dev.main.drupal$ git status On branch master
Your branch is ahead of 'origin/master' by 4 commits.
(use "git push" to publish your local commits)

Untracked files: (use "git add ..." to include in what will be committed)
sites/all/themes/base/sass/all/desktop/
sites/all/themes/base/sass/all/mobile/
sites/all/themes/base/sass/all/pages/
sites/all/themes/base/sass/all/print/
sites/all/themes/base/sass/all/sidebar/

But i don't want to push track / push these files to master yet so I did not take any action rather went for a fresh pull.

git pull

Already up-to-date.

Next two commands created and pushed the new branch from master: git checkout -b php-merge-2016 git push -u origin php-merge-2016

Before checking out to the new branch I first did a git reset --hard

HEAD is now at bf25410 Merge branch 'master' of https://github.com/abcd/site.main.drupal

git checkout php-merge-2016

Switched to branch 'php-merge-2016'

While on this branch I ran git status which gave me the following (the folders only):

Untracked files:
(use "git add ..." to include in what will be committed)
sites/all/themes/base/sass/all/desktop/
sites/all/themes/base/sass/all/mobile/
sites/all/themes/base/sass/all/pages/
sites/all/themes/base/sass/all/print/
sites/all/themes/base/sass/all/sidebar/
nothing added to commit but untracked files present (use "git add" to track)

and then git status -u gives me individual files under each of the above folder:

On branch php-merge-2016 Untracked files:
(use "git add ..." to include in what will be committed)
sites/all/themes/base/sass/all/desktop/_article_block.scss
sites/all/themes/base/sass/all/desktop/_columns_sidebar_left_right.scss
sites/all/themes/base/sass/all/mobile/_block_winner_email_signup.scss
sites/all/themes/base/sass/all/mobile/_header.scss
sites/all/themes/base/sass/all/pages/_blog.scss
sites/all/themes/base/sass/all/pages/_branded_name_display.scss
sites/all/themes/base/sass/all/pages/_catalog.scss
sites/all/themes/base/sass/all/print/_general.scss sites/all/themes/base/sass/all/print/_print.scss sites/all/themes/base/sass/all/sidebar/_flyout.scss sites/all/themes/base/sass/all/sidebar/_get_local_info.scss sites/all/themes/base/sass/all/sidebar/_weather_widget.scss
nothing added to commit but untracked files present (use "git add" to track)

torek
  • 448,244
  • 59
  • 642
  • 775
Subrata Sarkar
  • 2,975
  • 6
  • 45
  • 85
  • The question would be muc easier to answer if you had the actual `git` commands together with their output for us... – AnoE Aug 17 '16 at 10:51
  • Hi, I have updated my question. Let me know if something is still missing. Thank you. – Subrata Sarkar Aug 17 '16 at 11:22
  • What happens if you simply delete the untracked directories? I would expect that it's absolute impossible for them to re-appear out of thin air by doing checkouts, pushes and pulls. Are they maybe automatically created by your build process, the webserver or whatever? – AnoE Aug 17 '16 at 11:30
  • If you are asking me to delete those untracked folders physically that cannot be done because they are part of the solution. I created those directories and files as a part of css merging process and committed to `css-merge-2016` branch. If I delete those directories/files the layout will mess up. – Subrata Sarkar Aug 17 '16 at 11:37
  • Well, if you added and committed them to your branch, then they are in that branch. So you should see them on that branch and on no other. Make double sure you actually added and committed them to the branch you need them on. – AnoE Aug 17 '16 at 11:44
  • When I tried `git checkout css-merge-2016` I could not switch. It says `The following untracked working tree files would be overwritten by checkout. Please move or remove them before you can switch branches. Aborting` and the same files are listed which are reported to be untracked under `php-merge-2016` branch. However if I use `git checkout -f ...` I can switch to it but getting `error: unable to unlink old 'sites/all/themes/base/sass/all/pages/_shipment.scss' (Permission denied)` - with all the files reported untracked in `php-merge-2016` branch. – Subrata Sarkar Aug 17 '16 at 11:58
  • Well, the "permission denied" is pretty important, good that you mentioned it. ;) Just a tip, it would have been helpful if you had posted the complete, unedited git output from the start (the "permission denied" would have been included there...). This is certainly the root of your problem. If git tries to move things around and cannot, you end up with corpses like this. Clean up the permissions... – AnoE Aug 17 '16 at 12:37
  • Sorry for my poor knowledge about git that I did not post the 'permission denied' thing. How do I clean up the permissions? – Subrata Sarkar Aug 17 '16 at 12:49
  • And will doing this physically delete or remove those files? Because one thread here says "Unlink" essentially means "delete file" in this case! – Subrata Sarkar Aug 17 '16 at 12:59
  • Permissions have nothing to with git, it's just the standard Unix permissions. `chmod`, `chown` as needed. Yes, `unlink` is Unix-speak for `delete`. This is getting a little bit basic, really... do you have a colleague you could ask to help you out? – AnoE Aug 17 '16 at 13:09
  • Sorry for bothering you like this. I am a freelancer and no body is sitting beside me. Just checked the permissions on those folders: `drwxr-xr-x 2 root root 4096 Aug 12 21:04 pages`, `drwxr-xr-x 2 root root 4096 Aug 16 18:18 print` But files under the folders are not owned by `root`, they are owned by my user. So if I update permissions of those folders and then try `git checkout` will it remove (unlink) all the files?! In fact those are important files and I do not want to unlink any of them – Subrata Sarkar Aug 17 '16 at 13:15
  • 1
    You are not bothering me, but it is cumbersome to do this kind of "support" in this way, and far away from what SO is about. If you are worried about losing files, make a backup and then play around. Get your permissions straight. git will generally not remove files when you do the normal commands (like checkout, branch, push, add, commit). You did `git reset --hard` often, it should not be necessary to do that all the time, try to avoid it. Try to avoid the `-f` option which forces `git` to do unsafe stuff. If you are getting stuck, clone the origin in a new directory and start over. – AnoE Aug 17 '16 at 13:56
  • I actually solved it finally by using `sudo chown -R /paht/to/folder`. Now no more permission error, no more untracked file. Working directories are clean under each branch. Thank you so much for showing me the way. And I would definitely like to thank my guru :) – Subrata Sarkar Aug 17 '16 at 14:27
  • Welcome, glad it's sorted. :) – AnoE Aug 17 '16 at 14:29

0 Answers0